2016-10-08 15:24:37 +02:00
|
|
|
package ls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/cmd"
|
|
|
|
"github.com/rclone/rclone/fs/config"
|
2019-10-11 17:55:04 +02:00
|
|
|
"github.com/rclone/rclone/fs/config/flags"
|
2016-10-08 15:24:37 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Globals
|
|
|
|
var (
|
|
|
|
listLong bool
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-10-11 17:58:11 +02:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2019-10-11 17:55:04 +02:00
|
|
|
cmdFlags := commandDefinition.Flags()
|
|
|
|
flags.BoolVarP(cmdFlags, &listLong, "long", "", listLong, "Show the type as well as names.")
|
2016-10-08 15:24:37 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 17:58:11 +02:00
|
|
|
var commandDefinition = &cobra.Command{
|
2016-10-08 15:24:37 +02: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 uses with the -l flag it lists the types too.
|
|
|
|
`,
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(0, 0, command, args)
|
2018-01-12 17:30:54 +01:00
|
|
|
remotes := config.FileSections()
|
2016-10-08 15:24:37 +02:00
|
|
|
sort.Strings(remotes)
|
|
|
|
maxlen := 1
|
|
|
|
for _, remote := range remotes {
|
|
|
|
if len(remote) > maxlen {
|
|
|
|
maxlen = len(remote)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, remote := range remotes {
|
|
|
|
if listLong {
|
2018-05-21 15:54:58 +02:00
|
|
|
remoteType := config.FileGet(remote, "type", "UNKNOWN")
|
2016-10-08 15:24:37 +02:00
|
|
|
fmt.Printf("%-*s %s\n", maxlen+1, remote+":", remoteType)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%s:\n", remote)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|