Skip to content

Commit

Permalink
Merge pull request #300 from gabriel-samfira/add-default-value
Browse files Browse the repository at this point in the history
Add a default value to the new --format option
  • Loading branch information
gabriel-samfira authored Sep 28, 2024
2 parents 5323fcb + f9abb30 commit 72e8aa1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 2 additions & 5 deletions cmd/garm-cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ var (
needsInit bool
debug bool
poolBalancerType string
outputFormat common.OutputFormat
errNeedsInitError = fmt.Errorf("please log into a garm installation first")
outputFormat common.OutputFormat = common.OutputFormatTable
errNeedsInitError = fmt.Errorf("please log into a garm installation first")
)

// rootCmd represents the base command when called without any subcommands
Expand All @@ -55,9 +55,6 @@ var rootCmd = &cobra.Command{
func Execute() {
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "Enable debug on all API calls")
rootCmd.PersistentFlags().VarP(&outputFormat, "format", "f", "Output format (table, json)")
if outputFormat.String() == "" {
outputFormat = common.OutputFormatTable
}

cobra.OnInitialize(initConfig)

Expand Down
9 changes: 6 additions & 3 deletions cmd/garm-cli/common/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const (
OutputFormatJSON OutputFormat = "json"
)

func (o OutputFormat) String() string {
return string(o)
func (o *OutputFormat) String() string {
if o == nil {
return ""
}
return string(*o)
}

func (o *OutputFormat) Set(value string) error {
Expand All @@ -23,6 +26,6 @@ func (o *OutputFormat) Set(value string) error {
return nil
}

func (o OutputFormat) Type() string {
func (o *OutputFormat) Type() string {
return "string"
}

0 comments on commit 72e8aa1

Please sign in to comment.