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.
This commit is contained in:
Nick Craig-Wood 2022-02-07 15:09:03 +00:00
parent 8dc93f1792
commit c40129d610
2 changed files with 19 additions and 0 deletions

View File

@ -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,

View File

@ -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