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

Function setRun

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

Source from the content-addressed store, hash-verified

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