| 24 | } |
| 25 | |
| 26 | func NewCmdConfigSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command { |
| 27 | opts := &SetOptions{ |
| 28 | IO: f.IOStreams, |
| 29 | } |
| 30 | |
| 31 | cmd := &cobra.Command{ |
| 32 | Use: "set <key> <value>", |
| 33 | Short: "Update configuration with a value for the given key", |
| 34 | Example: heredoc.Doc(` |
| 35 | $ gh config set editor vim |
| 36 | $ gh config set editor "code --wait" |
| 37 | $ gh config set git_protocol ssh --host github.com |
| 38 | $ gh config set api_host api-gateway.example.com --host example.com |
| 39 | $ gh config set prompt disabled |
| 40 | `), |
| 41 | Args: cobra.ExactArgs(2), |
| 42 | RunE: func(cmd *cobra.Command, args []string) error { |
| 43 | config, err := f.Config() |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | opts.Config = config |
| 48 | opts.Key = args[0] |
| 49 | opts.Value = args[1] |
| 50 | |
| 51 | if runF != nil { |
| 52 | return runF(opts) |
| 53 | } |
| 54 | |
| 55 | return setRun(opts) |
| 56 | }, |
| 57 | } |
| 58 | |
| 59 | cmd.Flags().StringVarP(&opts.Hostname, "host", "h", "", "Set per-host setting") |
| 60 | |
| 61 | return cmd |
| 62 | } |
| 63 | |
| 64 | func setRun(opts *SetOptions) error { |
| 65 | if isPerHostOnly(opts.Key) && opts.Hostname == "" { |