From 54440c1481fed4d7342ee72da45759e023d594ba Mon Sep 17 00:00:00 2001 From: Gabriela Limberea Date: Tue, 10 Oct 2023 14:42:26 +0300 Subject: [PATCH] enabled new api-compliant json output format --- commands/root.go | 5 +++-- pkg/jsontabwriter/jsontabwriter.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/commands/root.go b/commands/root.go index 309ea1f30..964f689a4 100644 --- a/commands/root.go +++ b/commands/root.go @@ -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" @@ -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") diff --git a/pkg/jsontabwriter/jsontabwriter.go b/pkg/jsontabwriter/jsontabwriter.go index 5c1d26e0e..87043f1d1 100644 --- a/pkg/jsontabwriter/jsontabwriter.go +++ b/pkg/jsontabwriter/jsontabwriter.go @@ -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)