Skip to content

Commit

Permalink
remove --json flag from all commands and CLIContext
Browse files Browse the repository at this point in the history
gaiad tendermint show-{address,validator} now take --machine-parseable/-m
for machine parseable output.

Closes: #3249
  • Loading branch information
Alessio Treglia committed Jan 23, 2019
1 parent b5e245f commit 92ae60b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
2 changes: 2 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BREAKING CHANGES
in order to trigger a simulation of the tx before the actual execution.
* [\#3285](https://github.com/cosmos/cosmos-sdk/pull/3285) New `gaiad tendermint version` to print libs versions
* [\#1894](https://github.com/cosmos/cosmos-sdk/pull/1894) `version` command now shows latest commit, vendor dir hash, and build machine info.
* [\#3249\(https://github.com/cosmos/cosmos-sdk/issues/3249) `tendermint`'s `show-validator` and `show-address` `--json` flags removed in favor of `--machine-parseable`.

* SDK
* [staking] \#2513 Validator power type from Dec -> Int
Expand Down Expand Up @@ -99,6 +100,7 @@ IMPROVEMENTS

* Gaia CLI (`gaiacli`)
* [\#3224](https://github.com/cosmos/cosmos-sdk/pull/3224) Support adding offline public keys to the keystore
* [\#3249\(https://github.com/cosmos/cosmos-sdk/issues/3249) `--json` flag removed, users should use `--output=json` instead.

* Gaia
* [\#2186](https://github.com/cosmos/cosmos-sdk/issues/2186) Add Address Interface
Expand Down
4 changes: 2 additions & 2 deletions client/context/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (ctx CLIContext) broadcastTxAsync(txBytes []byte) (*ctypes.ResultBroadcastT
}

if ctx.Output != nil {
if ctx.JSON {
if ctx.OutputFormat == "json" {
type toJSON struct {
TxHash string
}
Expand All @@ -131,7 +131,7 @@ func (ctx CLIContext) broadcastTxCommit(txBytes []byte) (*ctypes.ResultBroadcast
return res, err
}

if ctx.JSON {
if ctx.OutputFormat == "json" {
// Since JSON is intended for automated scripts, always include response in
// JSON mode.
type toJSON struct {
Expand Down
2 changes: 0 additions & 2 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type CLIContext struct {
TrustNode bool
UseLedger bool
Async bool
JSON bool
PrintResponse bool
Verifier tmlite.Verifier
Simulate bool
Expand Down Expand Up @@ -82,7 +81,6 @@ func NewCLIContext() CLIContext {
TrustNode: viper.GetBool(client.FlagTrustNode),
UseLedger: viper.GetBool(client.FlagUseLedger),
Async: viper.GetBool(client.FlagAsync),
JSON: viper.GetBool(client.FlagJson),
PrintResponse: viper.GetBool(client.FlagPrintResponse),
Verifier: verifier,
Simulate: viper.GetBool(client.FlagDryRun),
Expand Down
2 changes: 0 additions & 2 deletions client/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const (
FlagFees = "fees"
FlagGasPrices = "gas-prices"
FlagAsync = "async"
FlagJson = "json"
FlagPrintResponse = "print-response"
FlagDryRun = "dry-run"
FlagGenerateOnly = "generate-only"
Expand Down Expand Up @@ -86,7 +85,6 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
c.Flags().Bool(FlagUseLedger, false, "Use a connected Ledger device")
c.Flags().Float64(FlagGasAdjustment, DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ")
c.Flags().Bool(FlagAsync, false, "broadcast transactions asynchronously")
c.Flags().Bool(FlagJson, false, "return output in json format")
c.Flags().Bool(FlagPrintResponse, true, "return tx response (only works with async = false)")
c.Flags().Bool(FlagTrustNode, true, "Trust connected full node (don't verify proofs for responses)")
c.Flags().Bool(FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it")
Expand Down
12 changes: 6 additions & 6 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestGaiaCLIGasAuto(t *testing.T) {
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf(denom).Int64())

// Enable auto gas
success, stdout, stderr := f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--gas=auto", "--json")
success, stdout, stderr := f.TxSend(keyFoo, barAddr, sdk.NewInt64Coin(denom, 10), "--gas=auto")
require.NotEmpty(t, stderr)
require.True(t, success)
cdc := app.MakeCodec()
Expand Down Expand Up @@ -646,7 +646,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
defer os.Remove(unsignedTxFile.Name())

// Test sign --validate-signatures
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name(), "--validate-signatures", "--json")
success, stdout, _ = f.TxSign(keyFoo, unsignedTxFile.Name(), "--validate-signatures")
require.False(t, success)
require.Equal(t, fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n\n", fooAddr.String()), stdout)

Expand All @@ -663,7 +663,7 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
defer os.Remove(signedTxFile.Name())

// Test sign --validate-signatures
success, stdout, _ = f.TxSign(keyFoo, signedTxFile.Name(), "--validate-signatures", "--json")
success, stdout, _ = f.TxSign(keyFoo, signedTxFile.Name(), "--validate-signatures")
require.True(t, success)
require.Equal(t, fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n 0: %v\t[OK]\n\n", fooAddr.String(),
fooAddr.String()), stdout)
Expand Down Expand Up @@ -736,7 +736,7 @@ func TestGaiaCLIMultisignInsufficientCosigners(t *testing.T) {
defer os.Remove(signedTxFile.Name())

// Validate the multisignature
success, _, _ = f.TxSign(keyFooBarBaz, signedTxFile.Name(), "--validate-signatures", "--json")
success, _, _ = f.TxSign(keyFooBarBaz, signedTxFile.Name(), "--validate-signatures")
require.False(t, success)

// Broadcast the transaction
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestGaiaCLIMultisignSortSignatures(t *testing.T) {
defer os.Remove(signedTxFile.Name())

// Validate the multisignature
success, _, _ = f.TxSign(keyFooBarBaz, signedTxFile.Name(), "--validate-signatures", "--json")
success, _, _ = f.TxSign(keyFooBarBaz, signedTxFile.Name(), "--validate-signatures")
require.True(t, success)

// Broadcast the transaction
Expand Down Expand Up @@ -861,7 +861,7 @@ func TestGaiaCLIMultisign(t *testing.T) {
defer os.Remove(signedTxFile.Name())

// Validate the multisignature
success, _, _ = f.TxSign(keyFooBarBaz, signedTxFile.Name(), "--validate-signatures", "--json")
success, _, _ = f.TxSign(keyFooBarBaz, signedTxFile.Name(), "--validate-signatures")
require.True(t, success)

// Broadcast the transaction
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (f *Fixtures) TxSign(signer, fileName string, flags ...string) (bool, strin

// TxBroadcast is gaiacli tx sign
func (f *Fixtures) TxBroadcast(fileName string, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("gaiacli tx broadcast %v --json %v", f.Flags(), fileName)
cmd := fmt.Sprintf("gaiacli tx broadcast %v %v", f.Flags(), fileName)
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), app.DefaultKeyPass)
}

Expand Down
15 changes: 7 additions & 8 deletions server/tm_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/codec"

tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
"github.com/tendermint/tendermint/p2p"
pvm "github.com/tendermint/tendermint/privval"
tversion "github.com/tendermint/tendermint/version"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
versionString = `Tendermint: %s
flagMachineReadable = "machine-readable"
versionString = `Tendermint: %s
ABCI: %s
BlockProtocol: %d
P2PProtocol: %d
Expand Down Expand Up @@ -55,7 +54,7 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command {
cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
valPubKey := privValidator.GetPubKey()

if viper.GetBool(client.FlagJson) {
if viper.GetBool(flagMachineReadable) {
return printlnJSON(valPubKey)
}

Expand All @@ -68,7 +67,7 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command {
return nil
},
}
cmd.Flags().Bool(client.FlagJson, false, "get machine parseable output")
cmd.Flags().BoolP(flagMachineReadable, "m", false, "get machine parseable output")
return &cmd
}

Expand All @@ -85,7 +84,7 @@ func ShowAddressCmd(ctx *Context) *cobra.Command {
cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
valConsAddr := (sdk.ConsAddress)(privValidator.GetAddress())

if viper.GetBool(client.FlagJson) {
if viper.GetBool(flagMachineReadable) {
return printlnJSON(valConsAddr)
}

Expand All @@ -94,7 +93,7 @@ func ShowAddressCmd(ctx *Context) *cobra.Command {
},
}

cmd.Flags().Bool(client.FlagJson, false, "get machine parseable output")
cmd.Flags().BoolP(flagMachineReadable, "m", false, "get machine parseable output")
return cmd
}

Expand Down

0 comments on commit 92ae60b

Please sign in to comment.