(key string, value string)
| 28 | } |
| 29 | |
| 30 | func (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 | } |
nothing calls this directly
no test coverage detected