lsf: Add 'm' format specifier to show the MimeType

This commit is contained in:
Nick Craig-Wood 2018-05-13 10:37:25 +01:00
parent aadbcce486
commit f77efc7649
3 changed files with 15 additions and 0 deletions

View File

@ -64,6 +64,7 @@ output:
t - modification time
h - hash
i - ID of object if known
m - MimeType 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.
@ -141,6 +142,8 @@ func Lsf(fsrc fs.Fs, out io.Writer) error {
list.AddHash(hashType)
case 'i':
list.AddID()
case 'm':
list.AddMimeType()
default:
return errors.Errorf("Unknown format character %q", char)
}

View File

@ -1430,6 +1430,13 @@ func (l *ListFormat) AddID() {
})
}
// AddMimeType adds file's MimeType to the output if known
func (l *ListFormat) AddMimeType() {
l.AppendOutput(func() string {
return fs.MimeTypeDirEntry(l.entry)
})
}
// AppendOutput adds string generated by specific function to printed output
func (l *ListFormat) AppendOutput(functionToAppend func() string) {
if len(l.output) > 0 {

View File

@ -716,6 +716,11 @@ func TestListFormat(t *testing.T) {
list.AddID()
_ = operations.ListFormatted(&items[0], &list) // Can't really check anything - at least it didn't panic!
list.SetOutput(nil)
list.AddMimeType()
assert.Contains(t, operations.ListFormatted(&items[0], &list), "/")
assert.Equal(t, "inode/directory", operations.ListFormatted(&items[1], &list))
list.SetOutput(nil)
list.AddSize()
assert.Equal(t, "1", operations.ListFormatted(&items[0], &list))