Skip to content

Commit

Permalink
Set proper default command output (#8628)
Browse files Browse the repository at this point in the history
* Set proper default command output

* Removed duplicated cmd.SetErr(cmd.ErrOrStderr()) and cmd.SetOut(cmd.OutOrStdout())

* Moved command initialization and added CHANGELOG

* fix: groom all uses of cmd.Print*

* Ran make format

Co-authored-by: Michael FIG <mfig@agoric.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
  • Loading branch information
4 people authored Apr 17, 2021
1 parent b4fc48c commit 96fe999
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Renamed `MarshalAny` and `UnmarshalAny` to `MarshalInterface` and `UnmarshalInterface` respectively. These functions must take an interface as parameter (not a concrete type nor `Any` object). Underneath they use `Any` wrapping for correct protobuf serialization.
* CLI: removed `--text` flag from `show-node-id` command; the text format for public keys is not used any more - instead we use ProtoJSON.
* (types) [\#9079](https://github.com/cosmos/cosmos-sdk/issues/9079) Add `AddAmount`/`SubAmount` methods to `sdk.Coin`.
* [\#8628](https://github.com/cosmos/cosmos-sdk/issues/8628) Commands no longer print outputs using `stderr` by default

### API Breaking Changes

Expand Down
6 changes: 0 additions & 6 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,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.
Expand Down Expand Up @@ -120,9 +117,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
Expand Down
3 changes: 0 additions & 3 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ Example:
f.Uint32(flagIndex, 0, "Address index number for HD derivation")
f.String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for")

cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr())

return cmd
}

Expand Down
2 changes: 0 additions & 2 deletions client/keys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ func runListCmd(cmd *cobra.Command, _ []string) error {
return err
}

cmd.SetOut(cmd.OutOrStdout())

if ok, _ := cmd.Flags().GetBool(flagListNames); !ok {
printInfos(cmd.OutOrStdout(), infos, clientCtx.OutputFormat)
return nil
Expand Down
2 changes: 1 addition & 1 deletion client/keys/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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
}

Expand Down
3 changes: 1 addition & 2 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
4 changes: 4 additions & 0 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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())

initClientCtx = client.ReadHomeFlag(initClientCtx, cmd)

initClientCtx, err := config.ReadFromClientConfig(initClientCtx)
Expand Down
1 change: 0 additions & 1 deletion version/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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
}

Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/cli/validate_sigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion x/authz/types/generic_authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions x/bank/types/send_authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion x/feegrant/types/filtered_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 96fe999

Please sign in to comment.