Skip to content

Commit 42b7345

Browse files
committed
Enable YAML output support
1 parent e9bee9a commit 42b7345

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

cli/cli.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func createCliCommandTree(cmd *cobra.Command) {
116116
cmd.RegisterFlagCompletionFunc("log-format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
117117
return validLogFormats, cobra.ShellCompDirectiveDefault
118118
})
119-
validOutputFormats := []string{"text", "json", "jsonmini"}
119+
validOutputFormats := []string{"text", "json", "jsonmini", "yaml"}
120120
cmd.PersistentFlags().StringVar(&outputFormat, "format", "text", tr("The output format for the logs, can be: %s", strings.Join(validOutputFormats, ", ")))
121121
cmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
122122
return validOutputFormats, cobra.ShellCompDirectiveDefault
@@ -148,6 +148,7 @@ func parseFormatString(arg string) (feedback.OutputFormat, bool) {
148148
"json": feedback.JSON,
149149
"jsonmini": feedback.JSONMini,
150150
"text": feedback.Text,
151+
"yaml": feedback.YAML,
151152
}[strings.ToLower(arg)]
152153

153154
return f, found

cli/feedback/feedback.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ func (fb *Feedback) Printf(format string, v ...interface{}) {
113113

114114
// Print behaves like fmt.Print but writes on the out writer and adds a newline.
115115
func (fb *Feedback) Print(v interface{}) {
116-
if fb.format == JSON || fb.format == JSONMini {
116+
switch fb.format {
117+
case JSON, JSONMini:
117118
fb.printJSON(v)
118-
} else {
119+
case YAML:
120+
fb.printYAML(v)
121+
default:
119122
fmt.Fprintln(fb.out, v)
120123
}
121124
}

cli/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func runVersionCommand(cmd *cobra.Command, args []string) {
6161
latestVersion := updater.ForceCheckForUpdate(currentVersion)
6262

6363
versionInfo := globals.VersionInfo
64-
if f := feedback.GetFormat(); (f == feedback.JSON || f == feedback.JSONMini) && latestVersion != nil {
64+
if f := feedback.GetFormat(); (f == feedback.JSON || f == feedback.JSONMini || f == feedback.YAML) && latestVersion != nil {
6565
// Set this only we managed to get the latest version
6666
versionInfo.LatestVersion = latestVersion.String()
6767
}

0 commit comments

Comments
 (0)