mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 07:29:35 +01:00
lsf: implement 'i' format for showing object ID - fixes #1476
This commit is contained in:
parent
826975c341
commit
909c3a92d6
@ -63,6 +63,7 @@ output:
|
||||
s - size
|
||||
t - modification time
|
||||
h - hash
|
||||
i - ID of object if known
|
||||
|
||||
So if you wanted the path, size and modification time, you would use
|
||||
--format "pst", or maybe --format "tsp" to put the path last.
|
||||
@ -138,6 +139,8 @@ func Lsf(fsrc fs.Fs, out io.Writer) error {
|
||||
list.AddSize()
|
||||
case 'h':
|
||||
list.AddHash(hashType)
|
||||
case 'i':
|
||||
list.AddID()
|
||||
default:
|
||||
return errors.Errorf("Unknown format character %q", char)
|
||||
}
|
||||
|
@ -1420,6 +1420,16 @@ func (l *ListFormat) AddHash(ht hash.Type) {
|
||||
})
|
||||
}
|
||||
|
||||
// AddID adds file's ID to the output if known
|
||||
func (l *ListFormat) AddID() {
|
||||
l.AppendOutput(func() string {
|
||||
if do, ok := l.entry.(fs.IDer); ok {
|
||||
return do.ID()
|
||||
}
|
||||
return ""
|
||||
})
|
||||
}
|
||||
|
||||
// AppendOutput adds string generated by specific function to printed output
|
||||
func (l *ListFormat) AppendOutput(functionToAppend func() string) {
|
||||
if len(l.output) > 0 {
|
||||
|
@ -712,6 +712,10 @@ func TestListFormat(t *testing.T) {
|
||||
list.AddModTime()
|
||||
assert.Equal(t, items[0].ModTime().Local().Format("2006-01-02 15:04:05"), operations.ListFormatted(&items[0], &list))
|
||||
|
||||
list.SetOutput(nil)
|
||||
list.AddID()
|
||||
_ = operations.ListFormatted(&items[0], &list) // Can't really check anything - at least it didn't panic!
|
||||
|
||||
list.SetOutput(nil)
|
||||
list.AddSize()
|
||||
assert.Equal(t, "1", operations.ListFormatted(&items[0], &list))
|
||||
|
Loading…
Reference in New Issue
Block a user