MCPcopy Index your code
hub / github.com/cli/cli / setRun

Function setRun

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

Source from the content-addressed store, hash-verified

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

Callers 2

NewCmdConfigSetFunction · 0.70
Test_setRunFunction · 0.70

Calls 8

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