@cryptotaxi247 / kubo / commits / 4e91469b9

refact(cmd/config): change string option to const

License: MIT Signed-off-by: chenminjian <727180553@qq.com>

chenminjian committed Jan 27, 2019 at 14:26 UTC 4e91469b90de63d0ea186e32e994b5c495bd7dbe
1 file changed +9 -8
core/commands/config.go
+9 -8
@@ -32,8 +32,9 @@ type ConfigField struct {
32 }
33
34 const (
35 - configBoolOptionName = "bool"
36 - configJSONOptionName = "json"
35 + configBoolOptionName = "bool"
36 + configJSONOptionName = "json"
37 + configDryRunOptionName = "dry-run"
38 )
39
40 var ConfigCmd = &cmds.Command{
@@ -82,7 +83,7 @@ Set the value of the 'Datastore.Path' key:
83 // This is a temporary fix until we move the private key out of the config file
84 switch strings.ToLower(key) {
85 case "identity", "identity.privkey":
85 - return fmt.Errorf("cannot show or change private key through API")
86 + return errors.New("cannot show or change private key through API")
87 default:
88 }
89
@@ -207,7 +208,7 @@ func scrubValue(m map[string]interface{}, key []string) error {
208 for _, k := range key[:len(key)-1] {
209 foundk, val, ok := find(cur, k)
210 if !ok {
210 - return fmt.Errorf("failed to find specified key")
211 + return errors.New("failed to find specified key")
212 }
213
214 if foundk != k {
@@ -309,7 +310,7 @@ var configProfileApplyCmd = &cmds.Command{
310 Tagline: "Apply profile to config.",
311 },
312 Options: []cmdkit.Option{
312 - cmdkit.BoolOption("dry-run", "print difference between the current config and the config that would be generated"),
313 + cmdkit.BoolOption(configDryRunOptionName, "print difference between the current config and the config that would be generated"),
314 },
315 Arguments: []cmdkit.Argument{
316 cmdkit.StringArg("profile", true, false, "The profile to apply to the config."),
@@ -320,7 +321,7 @@ var configProfileApplyCmd = &cmds.Command{
321 return fmt.Errorf("%s is not a profile", req.Arguments[0])
322 }
323
323 - dryRun, _ := req.Options["dry-run"].(bool)
324 + dryRun, _ := req.Options[configDryRunOptionName].(bool)
325 cfgRoot, err := cmdenv.GetConfigRoot(env)
326 if err != nil {
327 return err
@@ -473,12 +474,12 @@ func replaceConfig(r repo.Repo, file io.Reader) error {
474
475 keyF, err := getConfig(r, config.PrivKeySelector)
476 if err != nil {
476 - return fmt.Errorf("failed to get PrivKey")
477 + return errors.New("failed to get PrivKey")
478 }
479
480 pkstr, ok := keyF.Value.(string)
481 if !ok {
481 - return fmt.Errorf("private key in config was not a string")
482 + return errors.New("private key in config was not a string")
483 }
484
485 cfg.Identity.PrivKey = pkstr