rclone/cmd/listremotes/listremotes.go

56 lines
1.2 KiB
Go
Raw Normal View History

// Package ls provides the ls command.
2016-10-08 13:24:37 +00:00
package ls
import (
"fmt"
"sort"
"github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs/config"
"github.com/rclone/rclone/fs/config/flags"
2016-10-08 13:24:37 +00:00
"github.com/spf13/cobra"
)
// Globals
var (
listLong bool
)
func init() {
2019-10-11 15:58:11 +00:00
cmd.Root.AddCommand(commandDefinition)
cmdFlags := commandDefinition.Flags()
2021-08-16 09:30:01 +00:00
flags.BoolVarP(cmdFlags, &listLong, "long", "", listLong, "Show the type as well as names")
2016-10-08 13:24:37 +00:00
}
2019-10-11 15:58:11 +00:00
var commandDefinition = &cobra.Command{
2016-10-08 13:24:37 +00:00
Use: "listremotes",
Short: `List all the remotes in the config file.`,
Long: `
rclone listremotes lists all the available remotes from the config file.
When used with the ` + "`--long`" + ` flag it lists the types too.
2016-10-08 13:24:37 +00:00
`,
Annotations: map[string]string{
"versionIntroduced": "v1.34",
},
2016-10-08 13:24:37 +00:00
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(0, 0, command, args)
remotes := config.FileSections()
2016-10-08 13:24:37 +00:00
sort.Strings(remotes)
maxlen := 1
for _, remote := range remotes {
if len(remote) > maxlen {
maxlen = len(remote)
}
}
for _, remote := range remotes {
if listLong {
remoteType := config.FileGet(remote, "type")
2016-10-08 13:24:37 +00:00
fmt.Printf("%-*s %s\n", maxlen+1, remote+":", remoteType)
} else {
fmt.Printf("%s:\n", remote)
}
}
},
}