forked from TrueCloudLab/rclone
Add listremotes command - fixes #558
This commit is contained in:
parent
8a56a6836a
commit
ace1e21894
2 changed files with 50 additions and 0 deletions
|
@ -14,6 +14,7 @@ import (
|
||||||
_ "github.com/ncw/rclone/cmd/delete"
|
_ "github.com/ncw/rclone/cmd/delete"
|
||||||
_ "github.com/ncw/rclone/cmd/genautocomplete"
|
_ "github.com/ncw/rclone/cmd/genautocomplete"
|
||||||
_ "github.com/ncw/rclone/cmd/gendocs"
|
_ "github.com/ncw/rclone/cmd/gendocs"
|
||||||
|
_ "github.com/ncw/rclone/cmd/listremotes"
|
||||||
_ "github.com/ncw/rclone/cmd/ls"
|
_ "github.com/ncw/rclone/cmd/ls"
|
||||||
_ "github.com/ncw/rclone/cmd/lsd"
|
_ "github.com/ncw/rclone/cmd/lsd"
|
||||||
_ "github.com/ncw/rclone/cmd/lsl"
|
_ "github.com/ncw/rclone/cmd/lsl"
|
||||||
|
|
49
cmd/listremotes/listremotes.go
Normal file
49
cmd/listremotes/listremotes.go
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package ls
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/ncw/rclone/cmd"
|
||||||
|
"github.com/ncw/rclone/fs"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Globals
|
||||||
|
var (
|
||||||
|
listLong bool
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cmd.Root.AddCommand(listremotesCmd)
|
||||||
|
listremotesCmd.Flags().BoolVarP(&listLong, "long", "l", listLong, "Show the type as well as names.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var listremotesCmd = &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 := fs.ConfigFile.GetSectionList()
|
||||||
|
sort.Strings(remotes)
|
||||||
|
maxlen := 1
|
||||||
|
for _, remote := range remotes {
|
||||||
|
if len(remote) > maxlen {
|
||||||
|
maxlen = len(remote)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, remote := range remotes {
|
||||||
|
if listLong {
|
||||||
|
remoteType := fs.ConfigFile.MustValue(remote, "type", "UNKNOWN")
|
||||||
|
fmt.Printf("%-*s %s\n", maxlen+1, remote+":", remoteType)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%s:\n", remote)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in a new issue