lsf: add --files-only and --dirs-only flags
This commit is contained in:
parent
c74c3b37da
commit
0eba37d8f3
2 changed files with 40 additions and 0 deletions
|
@ -18,6 +18,8 @@ var (
|
||||||
dirSlash bool
|
dirSlash bool
|
||||||
recurse bool
|
recurse bool
|
||||||
hashType = fs.HashMD5
|
hashType = fs.HashMD5
|
||||||
|
filesOnly bool
|
||||||
|
dirsOnly bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -27,6 +29,8 @@ func init() {
|
||||||
flags.StringVarP(&separator, "separator", "s", ";", "Separator for the items in the format.")
|
flags.StringVarP(&separator, "separator", "s", ";", "Separator for the items in the format.")
|
||||||
flags.BoolVarP(&dirSlash, "dir-slash", "d", true, "Append a slash to directory names.")
|
flags.BoolVarP(&dirSlash, "dir-slash", "d", true, "Append a slash to directory names.")
|
||||||
flags.VarP(&hashType, "hash", "", "Use this hash when `h` is used in the format MD5|SHA-1|DropboxHash")
|
flags.VarP(&hashType, "hash", "", "Use this hash when `h` is used in the format MD5|SHA-1|DropboxHash")
|
||||||
|
flags.BoolVarP(&filesOnly, "files-only", "", false, "Only list files.")
|
||||||
|
flags.BoolVarP(&dirsOnly, "dirs-only", "", false, "Only list directories.")
|
||||||
commandDefintion.Flags().BoolVarP(&recurse, "recursive", "R", false, "Recurse into the listing.")
|
commandDefintion.Flags().BoolVarP(&recurse, "recursive", "R", false, "Recurse into the listing.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +62,12 @@ can be returned as an empty string if it isn't available on the object
|
||||||
the object and "UNSUPPORTED" if that object does not support that hash
|
the object and "UNSUPPORTED" if that object does not support that hash
|
||||||
type.
|
type.
|
||||||
|
|
||||||
|
For example to emulate the md5sum command you can use
|
||||||
|
|
||||||
|
rclone lsf -R --hash MD5 --format hp --separator " " --files-only .
|
||||||
|
|
||||||
|
(Though "rclone md5sum ." is an easier way of typing this.)
|
||||||
|
|
||||||
By default the separator is ";" this can be changed with the
|
By default the separator is ";" this can be changed with the
|
||||||
--separator flag. Note that separators aren't escaped in the path so
|
--separator flag. Note that separators aren't escaped in the path so
|
||||||
putting it last is a good strategy.
|
putting it last is a good strategy.
|
||||||
|
@ -100,6 +110,16 @@ func Lsf(fsrc fs.Fs, out io.Writer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
|
_, isDir := entry.(fs.Directory)
|
||||||
|
if isDir {
|
||||||
|
if filesOnly {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if dirsOnly {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
fmt.Fprintln(out, fs.ListFormatted(&entry, &list))
|
fmt.Fprintln(out, fs.ListFormatted(&entry, &list))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -112,6 +112,26 @@ subdir
|
||||||
;subdir
|
;subdir
|
||||||
`, buf.String())
|
`, buf.String())
|
||||||
|
|
||||||
|
buf = new(bytes.Buffer)
|
||||||
|
format = "p"
|
||||||
|
filesOnly = true
|
||||||
|
err = Lsf(f, buf)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, `file1
|
||||||
|
file2
|
||||||
|
file3
|
||||||
|
`, buf.String())
|
||||||
|
filesOnly = false
|
||||||
|
|
||||||
|
buf = new(bytes.Buffer)
|
||||||
|
format = "p"
|
||||||
|
dirsOnly = true
|
||||||
|
err = Lsf(f, buf)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, `subdir
|
||||||
|
`, buf.String())
|
||||||
|
dirsOnly = false
|
||||||
|
|
||||||
buf = new(bytes.Buffer)
|
buf = new(bytes.Buffer)
|
||||||
format = "t"
|
format = "t"
|
||||||
err = Lsf(f, buf)
|
err = Lsf(f, buf)
|
||||||
|
|
Loading…
Reference in a new issue