diff --git a/cmd/lsf/lsf.go b/cmd/lsf/lsf.go index 633732168..d05b277be 100644 --- a/cmd/lsf/lsf.go +++ b/cmd/lsf/lsf.go @@ -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) } diff --git a/fs/operations/operations.go b/fs/operations/operations.go index 88e69572c..c0998b696 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -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 { diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.go index aa294663d..a0cedbc43 100644 --- a/fs/operations/operations_test.go +++ b/fs/operations/operations_test.go @@ -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))