From c40129d610e0c589010c5977d03b06c594e842d9 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 7 Feb 2022 15:09:03 +0000 Subject: [PATCH] fs: allow backends to have aliases #5616 This allows a backend to have multiple aliases. These aliases are hidden from `rclone config` and the command line flags are hidden from the user. However the flags, environment varialbes and config for the alias will work just fine. --- fs/config/config.go | 3 +++ fs/registry.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/fs/config/config.go b/fs/config/config.go index ca5b0903d..65780c367 100644 --- a/fs/config/config.go +++ b/fs/config/config.go @@ -576,6 +576,9 @@ func fsOption() *fs.Option { Required: true, } for _, item := range fs.Registry { + if item.Hide { + continue + } example := fs.OptionExample{ Value: item.Name, Help: item.Description, diff --git a/fs/registry.go b/fs/registry.go index 4f51062e3..99ca53551 100644 --- a/fs/registry.go +++ b/fs/registry.go @@ -36,6 +36,10 @@ type RegInfo struct { Options Options // The command help, if any CommandHelp []CommandHelp + // Aliases - other names this backend is known by + Aliases []string + // Hide - if set don't show in the configurator + Hide bool } // FileName returns the on disk file name for this backend @@ -256,6 +260,18 @@ func Register(info *RegInfo) { info.Prefix = info.Name } Registry = append(Registry, info) + for _, alias := range info.Aliases { + // Copy the info block and rename and hide the alias and options + aliasInfo := *info + aliasInfo.Name = alias + aliasInfo.Prefix = alias + aliasInfo.Hide = true + aliasInfo.Options = append(Options(nil), info.Options...) + for i := range aliasInfo.Options { + aliasInfo.Options[i].Hide = OptionHideBoth + } + Registry = append(Registry, &aliasInfo) + } } // Find looks for a RegInfo object for the name passed in. The name