From 3b0b943abe166742a95a5666a47d210204c51bb0 Mon Sep 17 00:00:00 2001 From: "Aeneas Rekkas (arekkas)" Date: Sun, 4 Dec 2016 10:14:49 +0100 Subject: [PATCH] cmd/connect: allow passing values as flags --- cmd/connect.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/connect.go b/cmd/connect.go index 3fad26d3169..51fdd3c6a68 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -18,16 +18,25 @@ var connectCmd = &cobra.Command{ secret := "*********" fmt.Println("To keep the current value, press enter.") - if u := input("Cluster URL [" + c.ClusterURL + "]: "); u != "" { + if u, _ := cmd.Flags().GetString("url"); u != "" { + c.ClusterURL = u + } else if u := input("Cluster URL [" + c.ClusterURL + "]: "); u != "" { c.ClusterURL = u } - if u := input("Client ID [" + c.ClientID + "]: "); u != "" { + + if u, _ := cmd.Flags().GetString("id"); u != "" { + c.ClientID = u + } else if u := input("Client ID [" + c.ClientID + "]: "); u != "" { c.ClientID = u } + if c.ClientSecret == "" { secret = "empty" } - if u := input("Client Secret [" + secret + "]: "); u != "" { + + if u, _ := cmd.Flags().GetString("secret"); u != "" { + c.ClientSecret = u + } else if u := input("Client Secret [" + secret + "]: "); u != "" { c.ClientSecret = u } if err := c.Persist(); err != nil { @@ -49,4 +58,7 @@ func input(message string) string { func init() { RootCmd.AddCommand(connectCmd) + connectCmd.Flags().String("url", "", "The cluster URL.") + connectCmd.Flags().String("id", "", "The client id.") + connectCmd.Flags().String("secret", "", "The client secret. Be aware that the secret will be leaked to bash history and ~/.hydra.yml") }