2022-08-28 19:21:57 +08:00
|
|
|
// Package ls provides the ls command.
|
2016-10-08 21:24:37 +08:00
|
|
|
package ls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/cmd"
|
|
|
|
"github.com/rclone/rclone/fs/config"
|
2019-10-11 23:55:04 +08:00
|
|
|
"github.com/rclone/rclone/fs/config/flags"
|
2016-10-08 21:24:37 +08:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Globals
|
|
|
|
var (
|
|
|
|
listLong bool
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-10-11 23:58:11 +08:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2019-10-11 23:55:04 +08:00
|
|
|
cmdFlags := commandDefinition.Flags()
|
2023-07-11 01:34:10 +08:00
|
|
|
flags.BoolVarP(cmdFlags, &listLong, "long", "", listLong, "Show the type as well as names", "")
|
2016-10-08 21:24:37 +08:00
|
|
|
}
|
|
|
|
|
2019-10-11 23:58:11 +08:00
|
|
|
var commandDefinition = &cobra.Command{
|
2016-10-08 21:24:37 +08:00
|
|
|
Use: "listremotes",
|
2023-06-15 02:07:43 +08:00
|
|
|
Short: `List all the remotes in the config file and defined in environment variables.`,
|
2016-10-08 21:24:37 +08:00
|
|
|
Long: `
|
|
|
|
rclone listremotes lists all the available remotes from the config file.
|
|
|
|
|
2022-06-20 01:55:37 +08:00
|
|
|
When used with the ` + "`--long`" + ` flag it lists the types too.
|
2016-10-08 21:24:37 +08:00
|
|
|
`,
|
2022-11-27 06:40:49 +08:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.34",
|
|
|
|
},
|
2016-10-08 21:24:37 +08:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(0, 0, command, args)
|
2018-01-13 00:30:54 +08:00
|
|
|
remotes := config.FileSections()
|
2016-10-08 21:24:37 +08:00
|
|
|
sort.Strings(remotes)
|
|
|
|
maxlen := 1
|
|
|
|
for _, remote := range remotes {
|
|
|
|
if len(remote) > maxlen {
|
|
|
|
maxlen = len(remote)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, remote := range remotes {
|
|
|
|
if listLong {
|
2021-03-10 23:40:34 +08:00
|
|
|
remoteType := config.FileGet(remote, "type")
|
2016-10-08 21:24:37 +08:00
|
|
|
fmt.Printf("%-*s %s\n", maxlen+1, remote+":", remoteType)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%s:\n", remote)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|