Skip to content

Commit

Permalink
Remove flags that were not required
Browse files Browse the repository at this point in the history
* 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) <[email protected]>
  • Loading branch information
alexellis committed Feb 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 89bb8e3 commit ec41106
Showing 7 changed files with 22 additions and 7 deletions.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions cmd/increases.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion cmd/jobs.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 2 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 1 addition & 1 deletion cmd/runners.go
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions cmd/ssh_ls.go
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit ec41106

Please sign in to comment.