Skip to content

Commit e1a97d2

Browse files
committed
Apply suggestions from code review
1 parent 3ba2c02 commit e1a97d2

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
115115
* (baseapp) [#19970](https://github.com/cosmos/cosmos-sdk/pull/19970) Fix default config values to use no-op mempool as default.
116116
* (crypto) [#20027](https://github.com/cosmos/cosmos-sdk/pull/20027) secp256r1 keys now implement gogoproto's customtype interface.
117117
* (x/bank) [#20028](https://github.com/cosmos/cosmos-sdk/pull/20028) Align query with multi denoms for send-enabled.
118-
* (cli) [#20033](https://github.com/cosmos/cosmos-sdk/pull/20033) Respect output format from client ctx.
118+
* (client/v2) [#20033](https://github.com/cosmos/cosmos-sdk/pull/20033) Respect output format from client ctx.
119119

120120
### API Breaking Changes
121121

client/v2/autocli/common.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,30 @@ func enhanceCustomCmd(builder *Builder, cmd *cobra.Command, cmdType cmdType, mod
226226

227227
// outOrStdoutFormat formats the output based on the output flag and writes it to the command's output stream.
228228
func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error {
229-
clientCtx, err := client.GetClientTxContext(cmd)
230-
if err != nil {
231-
return err
229+
var clientCtx client.Context
230+
if v := cmd.Context().Value(client.ClientContextKey); v != nil {
231+
clientCtx = *(v.(*client.Context))
232+
} else {
233+
clientCtx = client.Context{}
234+
}
235+
236+
flagSet := cmd.Flags()
237+
if clientCtx.OutputFormat == "" || flagSet.Changed(flags.FlagOutput) {
238+
output, _ := flagSet.GetString(flags.FlagOutput)
239+
clientCtx = clientCtx.WithOutputFormat(output)
240+
}
241+
242+
if !clientCtx.IsAux || flagSet.Changed(flags.FlagAux) {
243+
isAux, _ := flagSet.GetBool(flags.FlagAux)
244+
if isAux {
245+
// If the user didn't explicitly set an --output flag, use JSON by default.
246+
if clientCtx.OutputFormat == "" || !flagSet.Changed(flags.FlagOutput) {
247+
clientCtx = clientCtx.WithOutputFormat(flags.OutputFormatJSON)
248+
}
249+
}
232250
}
233251

252+
var err error
234253
outputType := clientCtx.OutputFormat
235254
// if the output type is text, convert the json to yaml
236255
// if output type is json or nil, default to json

client/v2/internal/flags/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
// FlagNoProposal is the flag convert a gov proposal command into a normal command.
1818
// This is used to allow user of chains with custom authority to not use gov submit proposals for usual proposal commands.
1919
FlagNoProposal = "no-proposal"
20+
FlagAux = "aux"
2021
)
2122

2223
// List of supported output formats

0 commit comments

Comments
 (0)