MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / Set

Method Set

pkg/config/provider.go:30–59  ·  view source on GitHub ↗
(key string, value string)

Source from the content-addressed store, hash-verified

28}
29
30func (accessToken *FileConfigProvider) Set(key string, value string) error {
31 // have to make new viper so it only contains file value, no ENVs or Flags
32 configPath, err := EnsureConfigPath()
33 if err != nil {
34 return err
35 }
36
37 localViper := viper.New()
38 SetupConfigFile(localViper, configPath)
39
40 if err := localViper.ReadInConfig(); err != nil {
41 if _, ok := err.(viper.ConfigFileNotFoundError); ok {
42 // config file not found, we create it here and recover
43 if err = localViper.SafeWriteConfig(); err != nil {
44 return err
45 }
46 } else {
47 return err // any other error is unrecoverable; abort
48 }
49 }
50 if key != "" && !IsValidKey(key) {
51 return fmt.Errorf("the key '%s' is not a valid", key)
52 }
53 key = strings.ToLower(key)
54 localViper.Set(key, value)
55 if err := localViper.WriteConfig(); err != nil {
56 return err
57 }
58 return nil
59}

Callers

nothing calls this directly

Calls 4

EnsureConfigPathFunction · 0.85
SetupConfigFileFunction · 0.85
IsValidKeyFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected