Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Use Global Output Flag Instead of Local One
Browse files Browse the repository at this point in the history
Before I had a local flag for version but this now being replaced by
a single global flag for outputs as it will be required in multiple
commands.
  • Loading branch information
mainawycliffe committed Apr 12, 2020
1 parent 0e41b32 commit cad619e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func init() {
// this can be used to pass project alias to sub commands, incase having
// multiple projects
rootCmd.PersistentFlags().StringP("project", "P", "default", "The firebase project to use")
findUserCmd.PersistentFlags().StringP("output", "o", "", "A file where data from firebase will be saved.")
rootCmd.PersistentFlags().StringP("output", "o", "", "A file where data from firebase will be saved.")
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

Expand Down
26 changes: 14 additions & 12 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var (
commit = "none"
date = "unknown"
builtBy = "goreleaser"
output = "text"
)

// versionCmd represents the version command
Expand All @@ -26,23 +25,18 @@ var versionCmd = &cobra.Command{
Aliases: []string{"v"},
Short: "Version will output the current build information",
Run: func(cmd *cobra.Command, args []string) {
output, err := cmd.Flags().GetString("output")
if err != nil {
utils.StdOutError(os.Stderr, "Error reading output %s", err.Error())
os.Exit(1)
}
kamandaVersion := map[string]string{
"version": version,
"commitHash": commit,
"builtBy": builtBy,
"built": date,
"OS/Arch": fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
if output == "text" {
t := tabby.New()
t.AddLine("Version:", version)
t.AddLine("Release Date:", date)
t.AddLine("Commit Hash:", commit)
t.AddLine("Built by:", builtBy)
t.AddLine("OS/Arch:", fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
t.Print()
os.Exit(0)
}
if output == "json" {
output, err := json.Marshal(kamandaVersion)
if err != nil {
Expand All @@ -61,10 +55,18 @@ var versionCmd = &cobra.Command{
fmt.Printf("%s\n", output)
os.Exit(0)
}
// default to text output
t := tabby.New()
t.AddLine("Version:", version)
t.AddLine("Release Date:", date)
t.AddLine("Commit Hash:", commit)
t.AddLine("Built by:", builtBy)
t.AddLine("OS/Arch:", fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH))
t.Print()
os.Exit(0)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
versionCmd.Flags().StringVarP(&output, "output", "o", "text", "Output format. One of 'Text', 'yaml' or 'json'.")
}

0 comments on commit cad619e

Please sign in to comment.