2016-08-05 18:12:27 +02:00
|
|
|
package lsd
|
|
|
|
|
|
|
|
import (
|
2019-06-17 10:34:30 +02:00
|
|
|
"context"
|
2016-08-05 18:12:27 +02:00
|
|
|
"os"
|
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/cmd"
|
|
|
|
"github.com/rclone/rclone/cmd/ls/lshelp"
|
|
|
|
"github.com/rclone/rclone/fs"
|
2019-10-11 17:55:04 +02:00
|
|
|
"github.com/rclone/rclone/fs/config/flags"
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs/operations"
|
2016-08-05 18:12:27 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-04-25 22:06:42 +02:00
|
|
|
var (
|
|
|
|
recurse bool
|
|
|
|
)
|
|
|
|
|
2016-08-05 18:12:27 +02:00
|
|
|
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, &recurse, "recursive", "R", false, "Recurse into the listing.")
|
2016-08-05 18:12:27 +02:00
|
|
|
}
|
|
|
|
|
2019-10-11 17:58:11 +02:00
|
|
|
var commandDefinition = &cobra.Command{
|
2016-08-05 18:12:27 +02:00
|
|
|
Use: "lsd remote:path",
|
2016-12-31 18:20:31 +01:00
|
|
|
Short: `List all directories/containers/buckets in the path.`,
|
2018-01-06 18:00:20 +01:00
|
|
|
Long: `
|
2018-04-25 22:06:42 +02: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 18:00:20 +01:00
|
|
|
` + lshelp.Help,
|
2016-08-05 18:12:27 +02:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
2020-11-05 12:33:32 +01:00
|
|
|
ci := fs.GetConfig(context.Background())
|
2016-08-05 18:12:27 +02:00
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
2018-04-25 22:06:42 +02:00
|
|
|
if recurse {
|
2020-11-05 12:33:32 +01:00
|
|
|
ci.MaxDepth = 0
|
2018-04-25 22:06:42 +02:00
|
|
|
}
|
2016-08-05 18:12:27 +02:00
|
|
|
fsrc := cmd.NewFsSrc(args)
|
2016-12-04 17:52:24 +01:00
|
|
|
cmd.Run(false, false, command, func() error {
|
2019-06-17 10:34:30 +02:00
|
|
|
return operations.ListDir(context.Background(), fsrc, os.Stdout)
|
2016-08-05 18:12:27 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|