Merge PR #1983: CLI UX Updates #1

This commit is contained in:
Christopher Goes 2018-08-22 12:51:31 +02:00 committed by GitHub
commit 29634bfd1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 13 deletions

17
Gopkg.lock generated
View File

@ -490,6 +490,14 @@
revision = "013b9cef642f875634c614019ab13b17570778ad" revision = "013b9cef642f875634c614019ab13b17570778ad"
version = "v0.23.0" version = "v0.23.0"
[[projects]]
digest = "1:bf6d9a827ea3cad964c2f863302e4f6823170d0b5ed16f72cf1184a7c615067e"
name = "github.com/tendermint/tmlibs"
packages = ["cli"]
pruneopts = "UT"
revision = "49596e0a1f48866603813df843c9409fc19805c6"
version = "v0.9.0"
[[projects]] [[projects]]
digest = "1:4dcb0dd65feecb068ce23a234d1a07c7868a1e39f52a6defcae0bb371d03abf6" digest = "1:4dcb0dd65feecb068ce23a234d1a07c7868a1e39f52a6defcae0bb371d03abf6"
name = "github.com/zondax/ledger-goclient" name = "github.com/zondax/ledger-goclient"
@ -499,7 +507,7 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:7a71fffde456d746c52f9cd09c50b034533a3180fb1f6320abb149f2ccc579e5" digest = "1:27507554c6d4f060d8d700c31c624a43d3a92baa634e178ddc044bdf7d13b44a"
name = "golang.org/x/crypto" name = "golang.org/x/crypto"
packages = [ packages = [
"blowfish", "blowfish",
@ -518,7 +526,7 @@
"salsa20/salsa", "salsa20/salsa",
] ]
pruneopts = "UT" pruneopts = "UT"
revision = "aabede6cba87e37f413b3e60ebfc214f8eeca1b0" revision = "614d502a4dac94afa3a6ce146bd1736da82514c6"
[[projects]] [[projects]]
digest = "1:d36f55a999540d29b6ea3c2ea29d71c76b1d9853fdcd3e5c5cb4836f2ba118f1" digest = "1:d36f55a999540d29b6ea3c2ea29d71c76b1d9853fdcd3e5c5cb4836f2ba118f1"
@ -538,14 +546,14 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:ead82e3e398388679f3ad77633a087ac31a47a6be59ae20841e1d1b3a3fbbd22" digest = "1:a0e12bc26f317c0e2d497baf767285e1790e526e8dd46553c5a67fcbc8692157"
name = "golang.org/x/sys" name = "golang.org/x/sys"
packages = [ packages = [
"cpu", "cpu",
"unix", "unix",
] ]
pruneopts = "UT" pruneopts = "UT"
revision = "1a700e749ce29638d0bbcb531cce1094ea096bd3" revision = "3b58ed4ad3395d483fc92d5d14123ce2c3581fec"
[[projects]] [[projects]]
digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18"
@ -666,6 +674,7 @@
"github.com/tendermint/tendermint/rpc/lib/server", "github.com/tendermint/tendermint/rpc/lib/server",
"github.com/tendermint/tendermint/types", "github.com/tendermint/tendermint/types",
"github.com/tendermint/tendermint/version", "github.com/tendermint/tendermint/version",
"github.com/tendermint/tmlibs/cli",
"github.com/zondax/ledger-goclient", "github.com/zondax/ledger-goclient",
"golang.org/x/crypto/blowfish", "golang.org/x/crypto/blowfish",
"golang.org/x/crypto/ripemd160", "golang.org/x/crypto/ripemd160",

View File

@ -8,9 +8,12 @@ BREAKING CHANGES
* Gaia CLI (`gaiacli`) * Gaia CLI (`gaiacli`)
* [x/stake] Validator.Owner renamed to Validator.Operator * [x/stake] Validator.Owner renamed to Validator.Operator
* [cli] unsafe_reset_all, show_validator, and show_node_id have been renamed to unsafe-reset-all, show-validator, and show-node-id * [cli] unsafe_reset_all, show_validator, and show_node_id have been renamed to unsafe-reset-all, show-validator, and show-node-id
* [cli] \#1983 --print-response now defaults to true in commands that create and send a transaction
* [cli] \#1983 you can now pass --pubkey or --address to gaiacli keys show to return a plaintext representation of the key's address or public key for use with other commands
* [cli] \#2061 changed proposalID in governance REST endpoints to proposal-id * [cli] \#2061 changed proposalID in governance REST endpoints to proposal-id
* [cli] \#2014 `gaiacli advanced` no longer exists - to access `ibc`, `rest-server`, and `validator-set` commands use `gaiacli ibc`, `gaiacli rest-server`, and `gaiacli tendermint`, respectively * [cli] \#2014 `gaiacli advanced` no longer exists - to access `ibc`, `rest-server`, and `validator-set` commands use `gaiacli ibc`, `gaiacli rest-server`, and `gaiacli tendermint`, respectively
* Gaia * Gaia
* Make the transient store key use a distinct store key. [#2013](https://github.com/cosmos/cosmos-sdk/pull/2013) * Make the transient store key use a distinct store key. [#2013](https://github.com/cosmos/cosmos-sdk/pull/2013)
* [x/stake] \#1901 Validator type's Owner field renamed to Operator; Validator's GetOwner() renamed accordingly to comply with the SDK's Validator interface. * [x/stake] \#1901 Validator type's Owner field renamed to Operator; Validator's GetOwner() renamed accordingly to comply with the SDK's Validator interface.

View File

@ -52,7 +52,7 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
c.Flags().Int64(FlagGas, 200000, "gas limit to set per-transaction") c.Flags().Int64(FlagGas, 200000, "gas limit to set per-transaction")
c.Flags().Bool(FlagAsync, false, "broadcast transactions asynchronously") c.Flags().Bool(FlagAsync, false, "broadcast transactions asynchronously")
c.Flags().Bool(FlagJson, false, "return output in json format") c.Flags().Bool(FlagJson, false, "return output in json format")
c.Flags().Bool(FlagPrintResponse, false, "return tx response (only works with async = false)") c.Flags().Bool(FlagPrintResponse, true, "return tx response (only works with async = false)")
} }
return cmds return cmds
} }

View File

@ -4,10 +4,20 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
keys "github.com/cosmos/cosmos-sdk/crypto/keys" "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/pkg/errors"
"github.com/tendermint/tmlibs/cli"
)
const (
// FlagAddress is the flag for the user's address on the command line.
FlagAddress = "address"
// FlagPublicKey represents the user's public key on the command line.
FlagPublicKey = "pubkey"
) )
var showKeysCmd = &cobra.Command{ var showKeysCmd = &cobra.Command{
@ -18,13 +28,38 @@ var showKeysCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
name := args[0] name := args[0]
info, err := getKey(name) info, err := getKey(name)
if err == nil { if err != nil {
printInfo(info) return err
} }
return err
showAddress := viper.GetBool(FlagAddress)
showPublicKey := viper.GetBool(FlagPublicKey)
outputSet := cmd.Flag(cli.OutputFlag).Changed
if showAddress && showPublicKey {
return errors.New("cannot use both --address and --pubkey at once")
}
if outputSet && (showAddress || showPublicKey) {
return errors.New("cannot use --output with --address or --pubkey")
}
if showAddress {
printKeyAddress(info)
return nil
}
if showPublicKey {
printPubKey(info)
return nil
}
printInfo(info)
return nil
}, },
} }
func init() {
showKeysCmd.Flags().Bool(FlagAddress, false, "output the address only (overrides --output)")
showKeysCmd.Flags().Bool(FlagPublicKey, false, "output the public key only (overrides --output)")
}
func getKey(name string) (keys.Info, error) { func getKey(name string) (keys.Info, error) {
kb, err := GetKeyBase() kb, err := GetKeyBase()
if err != nil { if err != nil {

View File

@ -6,7 +6,7 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
keys "github.com/cosmos/cosmos-sdk/crypto/keys" "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/cli"
dbm "github.com/tendermint/tendermint/libs/db" dbm "github.com/tendermint/tendermint/libs/db"
@ -173,3 +173,19 @@ func printInfos(infos []keys.Info) {
func printKeyOutput(ko KeyOutput) { func printKeyOutput(ko KeyOutput) {
fmt.Printf("%s\t%s\t%s\t%s\n", ko.Name, ko.Type, ko.Address, ko.PubKey) fmt.Printf("%s\t%s\t%s\t%s\n", ko.Name, ko.Type, ko.Address, ko.PubKey)
} }
func printKeyAddress(info keys.Info) {
ko, err := Bech32KeyOutput(info)
if err != nil {
panic(err)
}
fmt.Println(ko.Address.String())
}
func printPubKey(info keys.Info) {
ko, err := Bech32KeyOutput(info)
if err != nil {
panic(err)
}
fmt.Println(ko.PubKey)
}

View File

@ -27,7 +27,20 @@ const (
func SearchTxCmd(cdc *wire.Codec) *cobra.Command { func SearchTxCmd(cdc *wire.Codec) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "txs", Use: "txs",
Short: "Search for all transactions that match the given tags", Short: "Search for all transactions that match the given tags.",
Long: strings.TrimSpace(`
Search for transactions that match the given tags. By default, transactions must match ALL tags
passed to the --tags option. To match any transaction, use the --any option.
For example:
$ gaiacli tendermint txs --tag test1,test2
will match any transaction tagged with both test1,test2. To match a transaction tagged with either
test1 or test2, use:
$ gaiacli tendermint txs --tag test1,test2 --any
`),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
tags := viper.GetStringSlice(flagTags) tags := viper.GetStringSlice(flagTags)
@ -52,7 +65,7 @@ func SearchTxCmd(cdc *wire.Codec) *cobra.Command {
// TODO: change this to false once proofs built in // TODO: change this to false once proofs built in
cmd.Flags().Bool(client.FlagTrustNode, true, "Don't verify proofs for responses") cmd.Flags().Bool(client.FlagTrustNode, true, "Don't verify proofs for responses")
cmd.Flags().StringSlice(flagTags, nil, "Tags that must match (may provide multiple)") cmd.Flags().StringSlice(flagTags, nil, "Comma-separated list of tags that must match")
cmd.Flags().Bool(flagAny, false, "Return transactions that match ANY tag, rather than ALL") cmd.Flags().Bool(flagAny, false, "Return transactions that match ANY tag, rather than ALL")
return cmd return cmd
} }

View File

@ -69,7 +69,7 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command {
func UnsafeResetAllCmd(ctx *Context) *cobra.Command { func UnsafeResetAllCmd(ctx *Context) *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "unsafe-reset-all", Use: "unsafe-reset-all",
Short: "Reset blockchain database, priv_validator.json file, and the logger", Short: "Resets the blockchain database, removes address book files, and resets priv_validator.json to the genesis state",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
cfg := ctx.Config cfg := ctx.Config
tcmd.ResetAll(cfg.DBDir(), cfg.P2P.AddrBookFile(), cfg.PrivValidatorFile(), ctx.Logger) tcmd.ResetAll(cfg.DBDir(), cfg.P2P.AddrBookFile(), cfg.PrivValidatorFile(), ctx.Logger)