forked from TrueCloudLab/rclone
fs: factor config override detection into its own function #5178
This commit is contained in:
parent
b9fd02039b
commit
6d28ea7ab5
1 changed files with 16 additions and 11 deletions
27
fs/fs.go
27
fs/fs.go
|
@ -125,6 +125,21 @@ func (os Options) Get(name string) *Option {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Overridden discovers which config items have been overridden in the
|
||||||
|
// configmap passed in, either by the config string, command line
|
||||||
|
// flags or environment variables
|
||||||
|
func (os Options) Overridden(m *configmap.Map) configmap.Simple {
|
||||||
|
var overridden = configmap.Simple{}
|
||||||
|
for i := range os {
|
||||||
|
opt := &os[i]
|
||||||
|
value, isSet := m.GetOverride(opt.Name)
|
||||||
|
if isSet {
|
||||||
|
overridden.Set(opt.Name, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return overridden
|
||||||
|
}
|
||||||
|
|
||||||
// OptionVisibility controls whether the options are visible in the
|
// OptionVisibility controls whether the options are visible in the
|
||||||
// configurator or the command line.
|
// configurator or the command line.
|
||||||
type OptionVisibility byte
|
type OptionVisibility byte
|
||||||
|
@ -1381,17 +1396,7 @@ func NewFs(ctx context.Context, path string) (Fs, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Now discover which config items have been overridden,
|
overridden := fsInfo.Options.Overridden(config)
|
||||||
// either by the config string, command line flags or
|
|
||||||
// environment variables
|
|
||||||
var overridden = configmap.Simple{}
|
|
||||||
for i := range fsInfo.Options {
|
|
||||||
opt := &fsInfo.Options[i]
|
|
||||||
value, isSet := config.GetOverride(opt.Name)
|
|
||||||
if isSet {
|
|
||||||
overridden.Set(opt.Name, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(overridden) > 0 {
|
if len(overridden) > 0 {
|
||||||
extraConfig := overridden.String()
|
extraConfig := overridden.String()
|
||||||
//Debugf(nil, "detected overriden config %q", extraConfig)
|
//Debugf(nil, "detected overriden config %q", extraConfig)
|
||||||
|
|
Loading…
Reference in a new issue