mirror of
https://github.com/rclone/rclone.git
synced 2024-11-27 10:50:03 +08:00
1fed2d910c
If you are using rclone a library you can decide to use the rclone config file system or not by calling configfile.LoadConfig(ctx) If you don't you will need to set `config.Data` to an implementation of `config.Storage`. Other changes - change interface of config.FileGet to remove unused default - remove MustValue from config.Storage interface - change GetValue to return string or bool like elsewhere in rclone - implement a default config file system which panics with helpful error - implement getWithDefault to replace the removed MustValue - don't embed goconfig.ConfigFile so we can change the methods
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package ls
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
|
|
"github.com/rclone/rclone/cmd"
|
|
"github.com/rclone/rclone/fs/config"
|
|
"github.com/rclone/rclone/fs/config/flags"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// Globals
|
|
var (
|
|
listLong bool
|
|
)
|
|
|
|
func init() {
|
|
cmd.Root.AddCommand(commandDefinition)
|
|
cmdFlags := commandDefinition.Flags()
|
|
flags.BoolVarP(cmdFlags, &listLong, "long", "", listLong, "Show the type as well as names.")
|
|
}
|
|
|
|
var commandDefinition = &cobra.Command{
|
|
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)
|
|
remotes := config.FileSections()
|
|
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")
|
|
fmt.Printf("%-*s %s\n", maxlen+1, remote+":", remoteType)
|
|
} else {
|
|
fmt.Printf("%s:\n", remote)
|
|
}
|
|
}
|
|
},
|
|
}
|