MCPcopy Create free account
hub / github.com/cli/cli / setRun

Function setRun

pkg/cmd/config/set/set.go:64–94  ·  view source on GitHub ↗
(opts *SetOptions)

Source from the content-addressed store, hash-verified

62}
63
64func setRun(opts *SetOptions) error {
65 if isPerHostOnly(opts.Key) && opts.Hostname == "" {
66 return cmdutil.FlagErrorf("--host required when setting %s", opts.Key)
67 }
68
69 err := ValidateKey(opts.Key)
70 if err != nil {
71 warningIcon := opts.IO.ColorScheme().WarningIcon()
72 fmt.Fprintf(opts.IO.ErrOut, "%s warning: '%s' is not a known configuration key\n", warningIcon, opts.Key)
73 }
74
75 err = ValidateValue(opts.Key, opts.Value)
76 if err != nil {
77 var invalidValue InvalidValueError
78 if errors.As(err, &invalidValue) {
79 var values []string
80 for _, v := range invalidValue.ValidValues {
81 values = append(values, fmt.Sprintf("'%s'", v))
82 }
83 return fmt.Errorf("failed to set %q to %q: valid values are %v", opts.Key, opts.Value, strings.Join(values, ", "))
84 }
85 }
86
87 opts.Config.Set(opts.Hostname, opts.Key, opts.Value)
88
89 err = opts.Config.Write()
90 if err != nil {
91 return fmt.Errorf("failed to write config to disk: %w", err)
92 }
93 return nil
94}
95
96func ValidateKey(key string) error {
97 for _, configKey := range config.Options {

Callers 2

NewCmdConfigSetFunction · 0.70
Test_setRunFunction · 0.70

Calls 10

FlagErrorfFunction · 0.92
isPerHostOnlyFunction · 0.85
ValidateKeyFunction · 0.85
ValidateValueFunction · 0.85
WarningIconMethod · 0.80
ColorSchemeMethod · 0.80
JoinMethod · 0.80
ErrorfMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65

Tested by 1

Test_setRunFunction · 0.56