2017-02-24 22:51:01 +00:00
|
|
|
package ls2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ncw/rclone/cmd"
|
|
|
|
"github.com/ncw/rclone/fs"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
recurse bool
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmd.Root.AddCommand(commandDefintion)
|
|
|
|
commandDefintion.Flags().BoolVarP(&recurse, "recursive", "R", false, "Recurse into the listing.")
|
|
|
|
}
|
|
|
|
|
|
|
|
var commandDefintion = &cobra.Command{
|
|
|
|
Use: "ls2 remote:path",
|
|
|
|
Short: `List directories and objects in the path.`,
|
|
|
|
Hidden: true,
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
|
|
|
fsrc := cmd.NewFsSrc(args)
|
|
|
|
cmd.Run(false, false, command, func() error {
|
|
|
|
return fs.Walk(fsrc, "", false, fs.ConfigMaxDepth(recurse), func(path string, entries fs.DirEntries, err error) error {
|
|
|
|
if err != nil {
|
2017-11-15 05:32:00 +00:00
|
|
|
fs.Stats.Error(err)
|
2017-02-24 22:51:01 +00:00
|
|
|
fs.Errorf(path, "error listing: %v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
for _, entry := range entries {
|
2017-06-30 12:37:29 +00:00
|
|
|
_, isDir := entry.(fs.Directory)
|
2017-02-24 22:51:01 +00:00
|
|
|
if isDir {
|
|
|
|
fmt.Println(entry.Remote() + "/")
|
|
|
|
} else {
|
|
|
|
fmt.Println(entry.Remote())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|