()
| 26 | configCommand.cmd.AddCommand(newConfigShowCommand()) |
| 27 | configCommand.cmd.AddCommand(newConfigSetCommand()) |
| 28 | configCommand.cmd.AddCommand(newConfigTrustLocalCommand()) |
| 29 | configCommand.cmd.AddCommand(newConfigUntrustLocalCommand()) |
| 30 | configCommand.cmd.AddCommand(newConfigTrustedLocalsCommand()) |
| 31 | |
| 32 | return configCommand |
| 33 | } |
| 34 | |
| 35 | func newConfigSetCommand() *cobra.Command { |
| 36 | return &cobra.Command{ |
| 37 | Use: "set <key> <value>", |
| 38 | Short: "Set a configuration value in the global config", |
| 39 | Example: ` hey config set base_url http://app.hey.localhost:3003 |
| 40 | hey config set base_url https://app.hey.com`, |
| 41 | Args: cobra.ExactArgs(2), |
| 42 | RunE: func(cmd *cobra.Command, args []string) error { |
| 43 | key, value := args[0], args[1] |
| 44 | |
| 45 | switch key { |
| 46 | case "base_url": |
| 47 | if err := cfg.SetFromFlag(key, value); err != nil { |
| 48 | return err |
| 49 | } |
| 50 | if err := cfg.SaveBaseURL(cfg.BaseURL); err != nil { |
| 51 | return err |
| 52 | } |
| 53 | case "onboarded": |
| 54 | onboarded, err := strconv.ParseBool(value) |
| 55 | if err != nil { |
| 56 | return apierr.ErrUsage(fmt.Sprintf("onboarded must be true or false (got %q)", value)) |
| 57 | } |
| 58 | if err := cfg.SaveOnboarded(onboarded); err != nil { |
| 59 | return err |
| 60 | } |
| 61 | default: |
| 62 | return apierr.ErrUsage(fmt.Sprintf("unknown config key: %s (available: base_url, onboarded)", key)) |
| 63 | } |
no test coverage detected