Skip to content

Commit

Permalink
Merge pull request #390 from reubenmiller/fix-set-session
Browse files Browse the repository at this point in the history
fix(set-session): only write json output if user provides --output json
  • Loading branch information
reubenmiller authored Jun 10, 2024
2 parents d19e0c4 + 992f45b commit 5be6aae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/sessions/set/set.manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (n *CmdSet) RunE(cmd *cobra.Command, args []string) error {
Username: handler.C8Yclient.Username,
}

outputFormat := cfg.GetOutputFormatWithDefault(config.OutputUnknown).String()
outputFormat := cfg.GetOutputFormatWithDefault(cmd, config.OutputUnknown).String()

// Write session details to stderr (for humans)
if outputFormat != config.OutputJSON.String() {
Expand Down
13 changes: 8 additions & 5 deletions pkg/config/cliConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1449,12 +1449,15 @@ func (c *Config) GetOutputFormat() OutputFormat {
}

// GetOutputFormat Get output format type, i.e. json, csv, table etc.
func (c *Config) GetOutputFormatWithDefault(fallback OutputFormat) OutputFormat {
if c.RawOutput() {
return OutputJSON
func (c *Config) GetOutputFormatWithDefault(cmd *cobra.Command, fallback OutputFormat) OutputFormat {
if !cmd.Flags().Changed("output") {
return fallback
}
format := c.viper.GetString(SettingsOutputFormat)
return fallback.FromString(format)
value, err := cmd.Flags().GetString("output")
if err != nil {
return fallback
}
return fallback.FromString(value)
}

// IsCSVOutput check if csv output is enabled
Expand Down

0 comments on commit 5be6aae

Please sign in to comment.