mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
config: make config file system pluggable
If you are using rclone a library you can decide to use the rclone
config file system or not by calling
configfile.LoadConfig(ctx)
If you don't you will need to set `config.Data` to an implementation
of `config.Storage`.
Other changes
- change interface of config.FileGet to remove unused default
- remove MustValue from config.Storage interface
- change GetValue to return string or bool like elsewhere in rclone
- implement a default config file system which panics with helpful error
- implement getWithDefault to replace the removed MustValue
- don't embed goconfig.ConfigFile so we can change the methods
This commit is contained in:
61
fs/config/default_storage.go
Normal file
61
fs/config/default_storage.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package config
|
||||
|
||||
// Default config.Storage which panics with a useful error when used
|
||||
type defaultStorage struct{}
|
||||
|
||||
var noConfigStorage = "internal error: no config file system found. Did you call configfile.LoadConfig(ctx)?"
|
||||
|
||||
// GetSectionList returns a slice of strings with names for all the
|
||||
// sections
|
||||
func (defaultStorage) GetSectionList() []string {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// HasSection returns true if section exists in the config file
|
||||
func (defaultStorage) HasSection(section string) bool {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// DeleteSection removes the named section and all config from the
|
||||
// config file
|
||||
func (defaultStorage) DeleteSection(section string) {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// GetKeyList returns the keys in this section
|
||||
func (defaultStorage) GetKeyList(section string) []string {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// GetValue returns the key in section with a found flag
|
||||
func (defaultStorage) GetValue(section string, key string) (value string, found bool) {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// SetValue sets the value under key in section
|
||||
func (defaultStorage) SetValue(section string, key string, value string) {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// DeleteKey removes the key under section
|
||||
func (defaultStorage) DeleteKey(section string, key string) bool {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// Load the config from permanent storage
|
||||
func (defaultStorage) Load() error {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// Save the config to permanent storage
|
||||
func (defaultStorage) Save() error {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// Serialize the config into a string
|
||||
func (defaultStorage) Serialize() (string, error) {
|
||||
panic(noConfigStorage)
|
||||
}
|
||||
|
||||
// Check the interface is satisfied
|
||||
var _ Storage = defaultStorage{}
|
||||
Reference in New Issue
Block a user