Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): status cmd cli support output text #17184

Merged
merged 8 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/rpc/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/rpc"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/testutil/network"
Expand Down Expand Up @@ -48,7 +49,7 @@ func (s *IntegrationTestSuite) TestStatusCommand() {
val0 := s.network.Validators[0]
cmd := rpc.StatusCommand()

out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{})
out, err := clitestutil.ExecTestCLICmd(val0.ClientCtx, cmd, []string{fmt.Sprintf("--%s=json", flags.FlagOutput)})
s.Require().NoError(err)

// Make sure the output has the validator moniker.
Expand Down
19 changes: 10 additions & 9 deletions client/rpc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rpc

import (
"context"
"encoding/json"

"github.com/cometbft/cometbft/p2p"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
Expand All @@ -16,17 +17,17 @@ import (
// ValidatorInfo is info about the node's validator, same as CometBFT,
// except that we use our own PubKey.
type validatorInfo struct {
Address []byte
PubKey cryptotypes.PubKey
VotingPower int64
Address []byte `json:"address"`
PubKey cryptotypes.PubKey `json:"pub_key"`
VotingPower int64 `json:"voting_power"`
}

// ResultStatus is node's info, same as CometBFT, except that we use our own
// PubKey.
type resultStatus struct {
NodeInfo p2p.DefaultNodeInfo
SyncInfo coretypes.SyncInfo
ValidatorInfo validatorInfo
NodeInfo p2p.DefaultNodeInfo `json:"node_info"`
SyncInfo coretypes.SyncInfo `json:"sync_info"`
ValidatorInfo validatorInfo `json:"validator_info"`
}

// StatusCommand returns the command to return the status of the network.
Expand Down Expand Up @@ -63,17 +64,17 @@ func StatusCommand() *cobra.Command {
},
}

output, err := clientCtx.LegacyAmino.MarshalJSON(statusWithPk)
output, err := json.Marshal(statusWithPk)
zakir-code marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

cmd.Println(string(output))
return nil
return clientCtx.PrintRaw(output)
zakir-code marked this conversation as resolved.
Show resolved Hide resolved
},
}

cmd.Flags().StringP(flags.FlagNode, "n", "tcp://localhost:26657", "Node to connect to")
cmd.Flags().StringP(flags.FlagOutput, "o", "text", "Output format (text|json)")

return cmd
}
Expand Down