diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index d35a6e2101a0..e8f001c1b6cd 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -1,6 +1,7 @@ package autocli import ( + "context" "fmt" "io" "time" @@ -8,6 +9,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/x/tx/signing/aminojson" "github.com/cockroachdb/errors" + "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" "google.golang.org/protobuf/reflect/protoreflect" @@ -112,9 +114,7 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript } cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error { - if noIndent, _ := cmd.Flags().GetBool(flags.FlagNoIndent); noIndent { - encoderOptions.Indent = "" - } + cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &b.ClientCtx)) clientConn, err := getClientConn(cmd) if err != nil { @@ -126,6 +126,10 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript return err } + if noIndent, _ := cmd.Flags().GetBool(flags.FlagNoIndent); noIndent { + encoderOptions.Indent = "" + } + enc := encoder(aminojson.NewEncoder(encoderOptions)) bz, err := enc.Marshal(output.Interface()) if err != nil {