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

Function setRun

pkg/cmd/config/set/set.go:38–83  ·  view source on GitHub ↗
(isPromptEnabled bool, ask question.Asker, key string, value string)

Source from the content-addressed store, hash-verified

36}
37
38func setRun(isPromptEnabled bool, ask question.Asker, key string, value string) error {
39 // have to make new viper so it only contains file value, no ENVs or Flags
40 configPath, err := config.EnsureConfigPath()
41 if err != nil {
42 return err
43 }
44
45 localViper := viper.New()
46 config.SetupConfigFile(localViper, configPath)
47
48 if err := localViper.ReadInConfig(); err != nil {
49 if _, ok := err.(viper.ConfigFileNotFoundError); ok {
50 // config file not found, we create it here and recover
51 if err = localViper.SafeWriteConfig(); err != nil {
52 return err
53 }
54 } else {
55 return err // any other error is unrecoverable; abort
56 }
57 }
58 if key != "" && !config.IsValidKey(key) {
59 return fmt.Errorf("the key '%s' is not a valid", key)
60 }
61 if isPromptEnabled && value == "" {
62 k, v, err := promptMissing(ask, key)
63 if err != nil {
64 return err
65 }
66 value = v
67 key = k
68 }
69 key = strings.ToLower(key)
70 if key == strings.ToLower(constants.ConfigNoPrompt) {
71 boolValue, err := strconv.ParseBool(value)
72 if err != nil {
73 return fmt.Errorf("the provided value %s is not valid for NoPrompt, please use true of false", value)
74 }
75 localViper.Set(key, boolValue)
76 } else {
77 localViper.Set(key, value)
78 }
79 if err := localViper.WriteConfig(); err != nil {
80 return err
81 }
82 return nil
83}
84
85func promptMissing(ask question.Asker, key string) (string, string, error) {
86 keys := []string{

Callers 1

NewCmdSetFunction · 0.85

Calls 5

EnsureConfigPathFunction · 0.92
SetupConfigFileFunction · 0.92
IsValidKeyFunction · 0.92
promptMissingFunction · 0.70
SetMethod · 0.65

Tested by

no test coverage detected