conduit/cmd/tunnel.go
Evan Reichard b8714e52de
All checks were successful
continuous-integration/drone/push Build is passing
wip 2
2025-09-21 18:41:47 -04:00

38 lines
861 B
Go

package cmd
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"reichard.io/conduit/client"
"reichard.io/conduit/config"
)
var tunnelCmd = &cobra.Command{
Use: "tunnel <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)
tunnel.Start()
},
}
func init() {
configDefs := config.GetConfigDefs[config.ClientConfig]()
for _, d := range configDefs {
tunnelCmd.Flags().String(d.Key, d.Default, d.Description)
}
}