backend: add description field for all backends

Fixes #4391
This commit is contained in:
Paul Stern 2023-12-02 19:27:55 +03:00 committed by Nick Craig-Wood
parent a3d19942bd
commit bb679a9def
3 changed files with 18 additions and 3 deletions

View File

@ -19,7 +19,7 @@ var (
func init() {
cmd.Root.AddCommand(commandDefinition)
cmdFlags := commandDefinition.Flags()
flags.BoolVarP(cmdFlags, &listLong, "long", "", listLong, "Show the type as well as names", "")
flags.BoolVarP(cmdFlags, &listLong, "long", "", listLong, "Show the type and the description as well as names", "")
}
var commandDefinition = &cobra.Command{
@ -28,7 +28,7 @@ var commandDefinition = &cobra.Command{
Long: `
rclone listremotes lists all the available remotes from the config file.
When used with the ` + "`--long`" + ` flag it lists the types too.
When used with the ` + "`--long`" + ` flag it lists the types and the descriptions too.
`,
Annotations: map[string]string{
"versionIntroduced": "v1.34",
@ -38,15 +38,21 @@ When used with the ` + "`--long`" + ` flag it lists the types too.
remotes := config.FileSections()
sort.Strings(remotes)
maxlen := 1
maxlentype := 1
for _, remote := range remotes {
if len(remote) > maxlen {
maxlen = len(remote)
}
t := config.FileGet(remote, "type")
if len(t) > maxlentype {
maxlentype = len(t)
}
}
for _, remote := range remotes {
if listLong {
remoteType := config.FileGet(remote, "type")
fmt.Printf("%-*s %s\n", maxlen+1, remote+":", remoteType)
description := config.FileGet(remote, "description")
fmt.Printf("%-*s %-*s %s\n", maxlen+1, remote+":", maxlentype+1, remoteType, description)
} else {
fmt.Printf("%s:\n", remote)
}

View File

@ -104,6 +104,7 @@ func TestCRUD(t *testing.T) {
"y", // type my own password
"secret", // password
"secret", // repeat
"n", // don't edit advanced config
"y", // looks good, save
})
require.NoError(t, config.NewRemote(ctx, "test"))

View File

@ -19,6 +19,13 @@ import (
// Registry of filesystems
var Registry []*RegInfo
// optDescription is a basic description option
var optDescription = Option{
Name: "description",
Help: "Description of the remote",
Advanced: true,
}
// RegInfo provides information about a filesystem
type RegInfo struct {
// Name of this fs
@ -283,6 +290,7 @@ func Register(info *RegInfo) {
if info.Prefix == "" {
info.Prefix = info.Name
}
info.Options = append(info.Options, optDescription)
Registry = append(Registry, info)
for _, alias := range info.Aliases {
// Copy the info block and rename and hide the alias and options