From 0902cff7401ae04517919dc689611ea07c375450 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Thu, 18 Feb 2021 11:28:25 +0100 Subject: [PATCH 1/5] Set proper default command output --- simapp/simd/cmd/root.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index f76948d59cd5..544c7dfea235 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -83,6 +83,12 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { a := appCreator{encodingConfig} server.AddCommands(rootCmd, simapp.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags) + // set the default command output properly + rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) { + cmd.SetOut(cmd.OutOrStdout()) + cmd.SetErr(cmd.ErrOrStderr()) + } + // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( rpc.StatusCommand(), From bd0f2c9080a1c984845632b1c7bdd0d96c36db86 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Thu, 18 Feb 2021 12:33:22 +0100 Subject: [PATCH 2/5] Removed duplicated cmd.SetErr(cmd.ErrOrStderr()) and cmd.SetOut(cmd.OutOrStdout()) --- client/flags/flags.go | 6 ------ client/keys/add.go | 3 --- client/keys/list.go | 2 -- server/export.go | 3 +-- version/command.go | 1 - x/auth/client/cli/tx_sign.go | 1 - 6 files changed, 1 insertion(+), 15 deletions(-) diff --git a/client/flags/flags.go b/client/flags/flags.go index 1afb55b46733..2b30c13931ad 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -88,9 +88,6 @@ func AddQueryFlagsToCmd(cmd *cobra.Command) { cmd.Flags().StringP(tmcli.OutputFlag, "o", "text", "Output format (text|json)") cmd.MarkFlagRequired(FlagChainID) - - cmd.SetErr(cmd.ErrOrStderr()) - cmd.SetOut(cmd.OutOrStdout()) } // AddTxFlagsToCmd adds common flags to a module tx command. @@ -119,9 +116,6 @@ func AddTxFlagsToCmd(cmd *cobra.Command) { cmd.Flags().String(FlagGas, "", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically (default %d)", GasFlagAuto, DefaultGasLimit)) cmd.MarkFlagRequired(FlagChainID) - - cmd.SetErr(cmd.ErrOrStderr()) - cmd.SetOut(cmd.OutOrStdout()) } // AddPaginationFlagsToCmd adds common pagination flags to cmd diff --git a/client/keys/add.go b/client/keys/add.go index ae937b5a4b0d..0744943e8eb1 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -77,9 +77,6 @@ the flag --nosort is set. cmd.Flags().Uint32(flagIndex, 0, "Address index number for HD derivation") cmd.Flags().String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for") - cmd.SetOut(cmd.OutOrStdout()) - cmd.SetErr(cmd.ErrOrStderr()) - return cmd } diff --git a/client/keys/list.go b/client/keys/list.go index de7681acc9c0..c520df66d1f7 100644 --- a/client/keys/list.go +++ b/client/keys/list.go @@ -34,8 +34,6 @@ func runListCmd(cmd *cobra.Command, _ []string) error { return err } - cmd.SetOut(cmd.OutOrStdout()) - if ok, _ := cmd.Flags().GetBool(flagListNames); !ok { output, _ := cmd.Flags().GetString(cli.OutputFlag) printInfos(cmd.OutOrStdout(), infos, output) diff --git a/server/export.go b/server/export.go index 8fd618028ba0..150add98e78d 100644 --- a/server/export.go +++ b/server/export.go @@ -109,8 +109,7 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com return nil }, } - cmd.SetOut(cmd.OutOrStdout()) - cmd.SetErr(cmd.ErrOrStderr()) + cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") cmd.Flags().Int64(FlagHeight, -1, "Export state from a particular height (-1 means latest height)") cmd.Flags().Bool(FlagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)") diff --git a/version/command.go b/version/command.go index bb632aea5b18..9291c0a8249f 100644 --- a/version/command.go +++ b/version/command.go @@ -17,7 +17,6 @@ func NewVersionCommand() *cobra.Command { Short: "Print the application binary version information", RunE: func(cmd *cobra.Command, _ []string) error { verInfo := NewInfo() - cmd.SetOut(cmd.OutOrStdout()) if long, _ := cmd.Flags().GetBool(flagLong); !long { cmd.Println(verInfo.Version) diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index 251282bb8e0c..71858113767b 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -143,7 +143,6 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { func setOutputFile(cmd *cobra.Command) (func(), error) { outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument) if outputDoc == "" { - cmd.SetOut(cmd.OutOrStdout()) return func() {}, nil } From 82cde2148673b9e1d623cadf54a3c1c514596f8e Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Thu, 18 Feb 2021 13:30:46 +0100 Subject: [PATCH 3/5] Moved command initialization and added CHANGELOG --- CHANGELOG.md | 1 + simapp/simd/cmd/root.go | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d3afda47ee5..cd3c51426cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Client Breaking Changes * [\#8363](https://github.com/cosmos/cosmos-sdk/issues/8363) Addresses no longer have a fixed 20-byte length. From the SDK modules' point of view, any 1-255 bytes-long byte array is a valid address. +* [\#8628](https://github.com/cosmos/cosmos-sdk/issues/8628) Commands no longer print outputs using `stderr` by default ### API Breaking Changes diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 544c7dfea235..e7e051813f10 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -52,6 +52,10 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { Use: "simd", Short: "simulation app", PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { + // set the default command outputs + cmd.SetOut(cmd.OutOrStdout()) + cmd.SetErr(cmd.ErrOrStderr()) + if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err } @@ -83,12 +87,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { a := appCreator{encodingConfig} server.AddCommands(rootCmd, simapp.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags) - // set the default command output properly - rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) { - cmd.SetOut(cmd.OutOrStdout()) - cmd.SetErr(cmd.ErrOrStderr()) - } - // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( rpc.StatusCommand(), From 8c78b32ba21bc63e6056b909cd23559feb0b8fbf Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Wed, 3 Mar 2021 10:47:33 -0600 Subject: [PATCH 4/5] fix: groom all uses of cmd.Print* --- client/keys/migrate.go | 4 ++-- x/auth/client/cli/validate_sigs.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/keys/migrate.go b/client/keys/migrate.go index 836a2655b087..831eddd8f257 100644 --- a/client/keys/migrate.go +++ b/client/keys/migrate.go @@ -87,7 +87,7 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error { } if len(oldKeys) == 0 { - cmd.Print("Migration Aborted: no keys to migrate") + cmd.PrintErrln("Migration Aborted: no keys to migrate") return nil } @@ -136,7 +136,7 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error { return err } } - cmd.Print("Migration Complete") + cmd.PrintErrln("Migration Complete") return err } diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index d8d6283a7990..03acf833f13d 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -101,7 +101,7 @@ func printAndValidateSigs( if !offline && success { accNum, accSeq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, sigAddr) if err != nil { - cmd.Printf("failed to get account: %s\n", sigAddr) + cmd.PrintErrf("failed to get account: %s\n", sigAddr) return false } From 75c2a083d9caab6efa0fe7f8151f29af23f99e44 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Tue, 13 Apr 2021 07:45:21 +0200 Subject: [PATCH 5/5] Ran make format --- x/authz/types/generic_authorization_test.go | 3 ++- x/bank/types/send_authorization_test.go | 5 +++-- x/feegrant/types/filtered_fee.go | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/x/authz/types/generic_authorization_test.go b/x/authz/types/generic_authorization_test.go index e3330d1c6594..2dda401c693f 100644 --- a/x/authz/types/generic_authorization_test.go +++ b/x/authz/types/generic_authorization_test.go @@ -3,9 +3,10 @@ package types_test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/x/authz/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/require" ) func TestGenericAuthorization(t *testing.T) { diff --git a/x/bank/types/send_authorization_test.go b/x/bank/types/send_authorization_test.go index 055a0b1fb0aa..45bb718cd847 100644 --- a/x/bank/types/send_authorization_test.go +++ b/x/bank/types/send_authorization_test.go @@ -3,11 +3,12 @@ package types_test import ( "testing" + "github.com/stretchr/testify/require" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/require" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) var ( diff --git a/x/feegrant/types/filtered_fee.go b/x/feegrant/types/filtered_fee.go index 99cf5f1731a9..ae34a687ff68 100644 --- a/x/feegrant/types/filtered_fee.go +++ b/x/feegrant/types/filtered_fee.go @@ -3,10 +3,11 @@ package types import ( "time" + proto "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - proto "github.com/gogo/protobuf/proto" ) // TODO: Revisit this once we have propoer gas fee framework.