mirror of
https://github.com/rclone/rclone.git
synced 2025-01-11 00:40:03 +01:00
lsf: Add 'm' format specifier to show the MimeType
This commit is contained in:
parent
aadbcce486
commit
f77efc7649
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user