From ec411063ff35167ffac27ab7ef8a86497f1f6e11 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Fri, 23 Feb 2024 15:03:55 +0000 Subject: [PATCH] Remove flags that were not required * Removes duplicate staff flags * Adds -j shortcut for json format * Adds json output format to ssh ls command Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- cmd/{agent-logs.go => agent_logs.go} | 0 cmd/{controller-logs.go => controller_logs.go} | 0 cmd/increases.go | 3 +-- cmd/jobs.go | 2 +- cmd/root.go | 5 ++--- cmd/runners.go | 2 +- cmd/ssh_ls.go | 17 +++++++++++++++++ 7 files changed, 22 insertions(+), 7 deletions(-) rename cmd/{agent-logs.go => agent_logs.go} (100%) rename cmd/{controller-logs.go => controller_logs.go} (100%) diff --git a/cmd/agent-logs.go b/cmd/agent_logs.go similarity index 100% rename from cmd/agent-logs.go rename to cmd/agent_logs.go diff --git a/cmd/controller-logs.go b/cmd/controller_logs.go similarity index 100% rename from cmd/controller-logs.go rename to cmd/controller_logs.go diff --git a/cmd/increases.go b/cmd/increases.go index 7bdd6ec..32f3f28 100644 --- a/cmd/increases.go +++ b/cmd/increases.go @@ -21,9 +21,8 @@ func makeIncreases() *cobra.Command { cmd.RunE = runIncreasesE - cmd.Flags().Bool("json", false, "Request output in JSON format") - cmd.Flags().Bool("staff", false, "Request staff increases") cmd.Flags().Int("days", 30, "The number of days to look back for increases") + cmd.Flags().BoolP("json", "j", false, "Request output in JSON format") return cmd } diff --git a/cmd/jobs.go b/cmd/jobs.go index 535316c..769a35a 100644 --- a/cmd/jobs.go +++ b/cmd/jobs.go @@ -29,7 +29,7 @@ func makeJobs() *cobra.Command { cmd.RunE = runJobsE - cmd.Flags().Bool("json", false, "Request output in JSON format") + cmd.Flags().BoolP("json", "j", false, "Request output in JSON format") return cmd } diff --git a/cmd/root.go b/cmd/root.go index 69823cb..37effa2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,11 +30,11 @@ https://github.com/self-actuated/actuated-cli root.PersistentFlags().String("token-value", "", "Personal Access Token") root.PersistentFlags().StringP("token", "t", "$HOME/.actuated/PAT", "File to read for Personal Access Token") - root.PersistentFlags().Bool("staff", false, "Execute the command as an actuated staff member") + root.PersistentFlags().BoolP("staff", "s", false, "Execute the command as an actuated staff member") root.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { if _, ok := os.LookupEnv("ACTUATED_URL"); !ok { - return fmt.Errorf("ACTUATED_URL environment variable is not set") + return fmt.Errorf(`ACTUATED_URL environment variable is not set, see the CLI tab in the dashboard for instructions`) } return nil } @@ -55,7 +55,6 @@ https://github.com/self-actuated/actuated-cli root.AddCommand(MakeVersion()) root.AddCommand(makeController()) - } func Execute() error { diff --git a/cmd/runners.go b/cmd/runners.go index 9694dcd..5ff087a 100644 --- a/cmd/runners.go +++ b/cmd/runners.go @@ -30,7 +30,7 @@ func makeRunners() *cobra.Command { cmd.RunE = runRunnersE cmd.Flags().Bool("images", false, "Show the image being used for the rootfs and Kernel") - cmd.Flags().Bool("json", false, "Request output in JSON format") + cmd.Flags().BoolP("json", "j", false, "Request output in JSON format") return cmd } diff --git a/cmd/ssh_ls.go b/cmd/ssh_ls.go index 22a448b..496c711 100644 --- a/cmd/ssh_ls.go +++ b/cmd/ssh_ls.go @@ -6,6 +6,7 @@ import ( "encoding/json" "net/http" "net/url" + "os" "sort" "strconv" "time" @@ -25,6 +26,8 @@ func makeSshList() *cobra.Command { Short: "List SSH sessions", } + cmd.Flags().BoolP("json", "j", false, "Request output in JSON format") + cmd.RunE = runSshListE return cmd @@ -66,6 +69,11 @@ func runSshListE(cmd *cobra.Command, args []string) error { } defer res.Body.Close() + jsonFormat, err := cmd.Flags().GetBool("json") + if err != nil { + return err + } + buf := bytes.NewBuffer(nil) table := tablewriter.NewWriter(buf) @@ -104,6 +112,15 @@ func runSshListE(cmd *cobra.Command, args []string) error { }) } + if jsonFormat { + e := json.NewEncoder(os.Stdout) + e.SetIndent("", " ") + if err := e.Encode(onlyActor); err != nil { + return err + } + return nil + } + table.Render() cmd.Print(buf.String())