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

Function setRun

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

Source from the content-addressed store, hash-verified

62}
63
64func setRun(opts *SetOptions) error {
65 if err := validateScope(opts.Key, opts.Hostname); err != nil {
66 return cmdutil.FlagErrorf("%s", err)
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 if invalidValue, ok := errors.AsType[InvalidValueError](err); ok {
78 var values []string
79 for _, v := range invalidValue.ValidValues {
80 values = append(values, fmt.Sprintf("'%s'", v))
81 }
82 return fmt.Errorf("failed to set %q to %q: valid values are %v", opts.Key, opts.Value, strings.Join(values, ", "))
83 }
84 }
85
86 opts.Config.Set(opts.Hostname, opts.Key, opts.Value)
87
88 err = opts.Config.Write()
89 if err != nil {
90 return fmt.Errorf("failed to write config to disk: %w", err)
91 }
92 return nil
93}
94
95func ValidateKey(key string) error {
96 for _, configKey := range config.Options {

Callers 2

NewCmdConfigSetFunction · 0.70
Test_setRunFunction · 0.70

Calls 10

FlagErrorfFunction · 0.92
validateScopeFunction · 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