-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/ref…
…actor-auth-tests
- Loading branch information
Showing
62 changed files
with
2,181 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"path/filepath" | ||
|
||
tmcli "github.com/tendermint/tendermint/libs/cli" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
) | ||
|
||
// Cmd returns a CLI command to interactively create an application CLI | ||
// config file. | ||
func Cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "config <key> [value]", | ||
Short: "Create or query an application CLI configuration file", | ||
RunE: runConfigCmd, | ||
Args: cobra.RangeArgs(0, 2), | ||
} | ||
return cmd | ||
} | ||
|
||
func runConfigCmd(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
configPath := filepath.Join(clientCtx.HomeDir, "config") | ||
|
||
conf, err := getClientConfig(configPath, clientCtx.Viper) | ||
if err != nil { | ||
return fmt.Errorf("couldn't get client config: %v", err) | ||
} | ||
|
||
switch len(args) { | ||
case 0: | ||
// print all client config fields to sdt out | ||
s, _ := json.MarshalIndent(conf, "", "\t") | ||
cmd.Println(string(s)) | ||
|
||
case 1: | ||
// it's a get | ||
key := args[0] | ||
|
||
switch key { | ||
case flags.FlagChainID: | ||
cmd.Println(conf.ChainID) | ||
case flags.FlagKeyringBackend: | ||
cmd.Println(conf.KeyringBackend) | ||
case tmcli.OutputFlag: | ||
cmd.Println(conf.Output) | ||
case flags.FlagNode: | ||
cmd.Println(conf.Node) | ||
case flags.FlagBroadcastMode: | ||
cmd.Println(conf.BroadcastMode) | ||
default: | ||
err := errUnknownConfigKey(key) | ||
return fmt.Errorf("couldn't get the value for the key: %v, error: %v", key, err) | ||
} | ||
|
||
case 2: | ||
// it's set | ||
key, value := args[0], args[1] | ||
|
||
switch key { | ||
case flags.FlagChainID: | ||
conf.SetChainID(value) | ||
case flags.FlagKeyringBackend: | ||
conf.SetKeyringBackend(value) | ||
case tmcli.OutputFlag: | ||
conf.SetOutput(value) | ||
case flags.FlagNode: | ||
conf.SetNode(value) | ||
case flags.FlagBroadcastMode: | ||
conf.SetBroadcastMode(value) | ||
default: | ||
return errUnknownConfigKey(key) | ||
} | ||
|
||
confFile := filepath.Join(configPath, "client.toml") | ||
if err := writeConfigToFile(confFile, conf); err != nil { | ||
return fmt.Errorf("could not write client config to the file: %v", err) | ||
} | ||
|
||
default: | ||
panic("cound not execute config command") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func errUnknownConfigKey(key string) error { | ||
return fmt.Errorf("unknown configuration key: %q", key) | ||
} |
Oops, something went wrong.