Skip to content

Commit

Permalink
enabled new api-compliant json output format
Browse files Browse the repository at this point in the history
  • Loading branch information
glimberea committed Oct 10, 2023
1 parent 846df5f commit 54440c1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/ionos-cloud/ionosctl/v6/commands/dns"
"github.com/ionos-cloud/ionosctl/v6/pkg/jsontabwriter"

container_registry "github.com/ionos-cloud/ionosctl/v6/commands/container-registry"

Expand Down Expand Up @@ -107,13 +108,13 @@ func init() {
_ = viper.BindPFlag(constants.ArgServerUrl, rootPFlagSet.Lookup(constants.ArgServerUrl))
rootPFlagSet.StringVarP(
&Output, constants.ArgOutput, constants.ArgOutputShort, constants.DefaultOutputFormat,
"Desired output format [text|json]",
"Desired output format [text|json|api-json]",
)
_ = viper.BindPFlag(constants.ArgOutput, rootPFlagSet.Lookup(constants.ArgOutput))
_ = rootCmd.Command.RegisterFlagCompletionFunc(
constants.ArgOutput,
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"json", "text"}, cobra.ShellCompDirectiveNoFileComp
return []string{jsontabwriter.JSONFormat, jsontabwriter.TextFormat, jsontabwriter.APIFormat}, cobra.ShellCompDirectiveNoFileComp
},
)
rootPFlagSet.BoolVarP(&Quiet, constants.ArgQuiet, constants.ArgQuietShort, false, "Quiet output")
Expand Down
2 changes: 1 addition & 1 deletion pkg/jsontabwriter/jsontabwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func generateLegacyJSONOutput(sourceData interface{}) (string, error) {
// I expect only one result from the query, so there is no need to loop through the results
queryResult, _ := query.Run(temp).Next()
if err, ok := queryResult.(error); ok && err != nil {
return string(apiOut), nil
return string(apiOut) + "\n", nil
}

return generateJSONOutputAPI(queryResult)
Expand Down

0 comments on commit 54440c1

Please sign in to comment.