From c29f6549848afb55e42bf61e457ed3a343d55e06 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Mon, 3 Jun 2019 21:30:13 +0530 Subject: [PATCH 1/2] Specify any custom format when using connect --- cmd/connect.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/connect.go b/cmd/connect.go index f20f24e..e18541b 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -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() @@ -127,13 +126,23 @@ 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) } } }, From 05f7c51e7a9457d974c1976708b3bac2edbfb16d Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Mon, 3 Jun 2019 21:32:16 +0530 Subject: [PATCH 2/2] Update help --- cmd/connect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/connect.go b/cmd/connect.go index e18541b..1c7adea 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -149,7 +149,7 @@ var connectCmd = &cobra.Command{ } 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")