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

Add client config #8820

Closed
48 changes: 36 additions & 12 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ type ClientConfig struct {
Trace bool `mapstructure:"trace" json:"trace"`
}

// TODO Validate values in setters
func (c *ClientConfig) SetChainID(chainID string) {
c.ChainID = chainID
}

func (c *ClientConfig) SetKeyringBackend(keyringBackend string) {
c.KeyringBackend = keyringBackend
}

func (c *ClientConfig) SetOutput(output string) {
c.Output = output
}

func (c *ClientConfig) SetNode(node string) {
c.Node = node
}

func (c *ClientConfig) SetBroadcastMode(broadcastMode string) {
c.BroadcastMode = broadcastMode
}

func (c *ClientConfig) SetTrace(trace string) error {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
boolVal, err := strconv.ParseBool(trace)
if err != nil {
return err
}
c.Trace = boolVal
return nil
}

func DefaultClientConfig() *ClientConfig {
return &ClientConfig{chainID, keyringBackend, output, node, broadcastMode, trace}
}
Expand All @@ -52,8 +82,6 @@ func Cmd(defaultCLIHome string) *cobra.Command {

cmd.Flags().String(flags.FlagHome, defaultCLIHome,
"set client's home directory for configuration")
// cmd.Flags().Bool(flagGet, false,
// "print configuration value or its default if unset")
return cmd
}

Expand Down Expand Up @@ -105,29 +133,25 @@ func runConfigCmd(cmd *cobra.Command, args []string) error {

case 2:
// it's set
// TODO impement method for set
// TODO implement setters

key, value := args[0], args[1]

switch key {
case flags.FlagChainID:
cliConfig.ChainID = value
cliConfig.SetChainID(value)
case flags.FlagKeyringBackend:
cliConfig.KeyringBackend = value
cliConfig.SetKeyringBackend(value)
case tmcli.OutputFlag:
cliConfig.Output = value
cliConfig.SetOutput(value)
case flags.FlagNode:
cliConfig.Node = value
cliConfig.SetNode(value)
case flags.FlagBroadcastMode:
cliConfig.BroadcastMode = value
cliConfig.SetBroadcastMode(value)
case "trace":
boolVal, err := strconv.ParseBool(value)
if err != nil {
if err := cliConfig.SetTrace(value); err != nil {
fmt.Fprintf(os.Stderr, "Unable to parse value to bool, err: %v\n", err)
return err
}
cliConfig.Trace = boolVal
default:
return errUnknownConfigKey(key)
}
Expand Down