Skip to content

Commit

Permalink
fix: respect output format from client ctx
Browse files Browse the repository at this point in the history
instead of flag only
  • Loading branch information
mmsqe committed Apr 13, 2024
1 parent 037cf98 commit 016bb5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* (baseapp) [#19970](https://github.com/cosmos/cosmos-sdk/pull/19970) Fix default config values to use no-op mempool as default.
* (crypto) [#20027](https://github.com/cosmos/cosmos-sdk/pull/20027) secp256r1 keys now implement gogoproto's customtype interface.
* (x/bank) [#20028](https://github.com/cosmos/cosmos-sdk/pull/20028) Align query with multi denoms for send-enabled.
* (cli) [#](https://github.com/cosmos/cosmos-sdk/pull/) Respect output format from client ctx.

### API Breaking Changes

Expand Down
12 changes: 9 additions & 3 deletions client/v2/autocli/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/client/v2/internal/flags"
"cosmossdk.io/client/v2/internal/util"

"github.com/cosmos/cosmos-sdk/client"
)

type cmdType int
Expand Down Expand Up @@ -224,11 +226,15 @@ func enhanceCustomCmd(builder *Builder, cmd *cobra.Command, cmdType cmdType, mod

// outOrStdoutFormat formats the output based on the output flag and writes it to the command's output stream.
func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error {
var err error
outputType := cmd.Flag(flags.FlagOutput)
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

outputType := clientCtx.OutputFormat
// if the output type is text, convert the json to yaml
// if output type is json or nil, default to json
if outputType != nil && outputType.Value.String() == flags.OutputFormatText {
if outputType == flags.OutputFormatText {
out, err = yaml.JSONToYAML(out)
if err != nil {
return err
Expand Down

0 comments on commit 016bb5e

Please sign in to comment.