Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(set-session): only write json output if user provides --output json #390

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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