From 6d28ea7ab52c694071ae0cedefa8272b9330d9db Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 3 Apr 2021 15:58:47 +0100 Subject: [PATCH] fs: factor config override detection into its own function #5178 --- fs/fs.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/fs/fs.go b/fs/fs.go index fa0d87722..4338be8c9 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -125,6 +125,21 @@ func (os Options) Get(name string) *Option { 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 // configurator or the command line. type OptionVisibility byte @@ -1381,17 +1396,7 @@ func NewFs(ctx context.Context, path string) (Fs, error) { if err != nil { return nil, err } - // Now discover which config items have been overridden, - // 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) - } - } + overridden := fsInfo.Options.Overridden(config) if len(overridden) > 0 { extraConfig := overridden.String() //Debugf(nil, "detected overriden config %q", extraConfig)