MCPcopy
hub / github.com/cli/cli / NewCmdConfigSet

Function NewCmdConfigSet

pkg/cmd/config/set/set.go:25–60  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*SetOptions) error)

Source from the content-addressed store, hash-verified

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

Callers 1

TestNewCmdConfigSetFunction · 0.85

Calls 2

setRunFunction · 0.70
ConfigMethod · 0.65

Tested by 1

TestNewCmdConfigSetFunction · 0.68