Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ var connectCmd = &cobra.Command{

format, _ := cmd.Flags().GetString("format")

if format != "ssh" {

if format == "" {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
defer w.Flush()

Expand All @@ -127,20 +126,30 @@ var connectCmd = &cobra.Command{
}

fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t\n", resp.Connection.Proxy, resp.Connection.DeviceAddress, resp.Status, resp.Connection.ExpirationInSeconds, resp.Connection.RequestedAt)

} else {
p := resp.Connection.Proxy
p = strings.Replace(strings.Replace(p, "http://", "", 1), "https://", "", 1)

parts := strings.Split(p, ":")

fmt.Printf("%s -p %s", parts[0], parts[1])
var formatted_proxy string
if format == "ssh" {
formatted_proxy = parts[0] + " -p " + parts[1]
} else {
formatted_proxy = strings.Replace(format, "{hostname}", parts[0], 1)
formatted_proxy = strings.Replace(formatted_proxy, "{port}", parts[1], 1)
formatted_proxy = strings.Replace(formatted_proxy, "{lastip}", lastIP, 1)
formatted_proxy = strings.Replace(formatted_proxy, "{address}", address, 1)
}
fmt.Printf("%s", formatted_proxy)
}
}
},
}

func init() {
connectCmd.PersistentFlags().String("format", "", "format for proxy connection (currently ssh is only valid value)")
connectCmd.PersistentFlags().String("format", "", "format for proxy connection (valid values: ssh, {hostname}, {port}, {lastip}, {address})")
viper.BindPFlag("format", loginCmd.PersistentFlags().Lookup("format"))

connectCmd.PersistentFlags().Bool("nocache", false, "do not use the local device cache, fetch device list fresh from remote.it")
Expand Down