2016-08-05 16:12:27 +00:00
|
|
|
package lsd
|
|
|
|
|
|
|
|
import (
|
2019-06-17 08:34:30 +00:00
|
|
|
"context"
|
2016-08-05 16:12:27 +00:00
|
|
|
"os"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/cmd"
|
|
|
|
"github.com/rclone/rclone/cmd/ls/lshelp"
|
|
|
|
"github.com/rclone/rclone/fs"
|
2019-10-11 15:55:04 +00:00
|
|
|
"github.com/rclone/rclone/fs/config/flags"
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs/operations"
|
2016-08-05 16:12:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-04-25 20:06:42 +00:00
|
|
|
var (
|
|
|
|
recurse bool
|
|
|
|
)
|
|
|
|
|
2016-08-05 16:12:27 +00:00
|
|
|
func init() {
|
2019-10-11 15:58:11 +00:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2019-10-11 15:55:04 +00:00
|
|
|
cmdFlags := commandDefinition.Flags()
|
|
|
|
flags.BoolVarP(cmdFlags, &recurse, "recursive", "R", false, "Recurse into the listing.")
|
2016-08-05 16:12:27 +00:00
|
|
|
}
|
|
|
|
|
2019-10-11 15:58:11 +00:00
|
|
|
var commandDefinition = &cobra.Command{
|
2016-08-05 16:12:27 +00:00
|
|
|
Use: "lsd remote:path",
|
2016-12-31 17:20:31 +00:00
|
|
|
Short: `List all directories/containers/buckets in the path.`,
|
2018-01-06 17:00:20 +00:00
|
|
|
Long: `
|
2018-04-25 20:06:42 +00:00
|
|
|
Lists the directories in the source path to standard output. Does not
|
|
|
|
recurse by default. Use the -R flag to recurse.
|
|
|
|
|
|
|
|
This command lists the total size of the directory (if known, -1 if
|
|
|
|
not), the modification time (if known, the current time if not), the
|
|
|
|
number of objects in the directory (if known, -1 if not) and the name
|
|
|
|
of the directory, Eg
|
|
|
|
|
|
|
|
$ rclone lsd swift:
|
|
|
|
494000 2018-04-26 08:43:20 10000 10000files
|
|
|
|
65 2018-04-26 08:43:20 1 1File
|
|
|
|
|
|
|
|
Or
|
|
|
|
|
|
|
|
$ rclone lsd drive:test
|
|
|
|
-1 2016-10-17 17:41:53 -1 1000files
|
|
|
|
-1 2017-01-03 14:40:54 -1 2500files
|
|
|
|
-1 2017-07-08 14:39:28 -1 4000files
|
|
|
|
|
|
|
|
If you just want the directory names use "rclone lsf --dirs-only".
|
|
|
|
|
2018-01-06 17:00:20 +00:00
|
|
|
` + lshelp.Help,
|
2016-08-05 16:12:27 +00:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
2018-04-25 20:06:42 +00:00
|
|
|
if recurse {
|
|
|
|
fs.Config.MaxDepth = 0
|
|
|
|
}
|
2016-08-05 16:12:27 +00:00
|
|
|
fsrc := cmd.NewFsSrc(args)
|
2016-12-04 16:52:24 +00:00
|
|
|
cmd.Run(false, false, command, func() error {
|
2019-06-17 08:34:30 +00:00
|
|
|
return operations.ListDir(context.Background(), fsrc, os.Stdout)
|
2016-08-05 16:12:27 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|