40 lines
928 B
Go
40 lines
928 B
Go
package cmd
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
"reichard.io/conduit/client"
|
|
"reichard.io/conduit/config"
|
|
)
|
|
|
|
var linkCmd = &cobra.Command{
|
|
Use: "link <name> <host:port>",
|
|
Short: "Create a conduit tunnel",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
// Get Client Config
|
|
cfg, err := config.GetClientConfig(cmd.Flags())
|
|
if err != nil {
|
|
log.Fatal("failed to get client config:", err)
|
|
}
|
|
|
|
// Create Tunnel
|
|
tunnel, err := client.NewTunnel(cfg)
|
|
if err != nil {
|
|
log.Fatal("failed to create tunnel:", err)
|
|
}
|
|
|
|
// Start Tunnel
|
|
log.Infof("creating TCP tunnel: %s -> %s", cfg.TunnelName, cfg.TunnelTarget)
|
|
if err := tunnel.Start(); err != nil {
|
|
log.Fatal("failed to start tunnel:", err)
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
configDefs := config.GetConfigDefs[config.ClientConfig]()
|
|
for _, d := range configDefs {
|
|
linkCmd.Flags().String(d.Key, d.Default, d.Description)
|
|
}
|
|
}
|