forked from TrueCloudLab/rclone
lsf: Add 'm' format specifier to show the MimeType
This commit is contained in:
parent
aadbcce486
commit
f77efc7649
3 changed files with 15 additions and 0 deletions
|
@ -64,6 +64,7 @@ output:
|
||||||
t - modification time
|
t - modification time
|
||||||
h - hash
|
h - hash
|
||||||
i - ID of object if known
|
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
|
So if you wanted the path, size and modification time, you would use
|
||||||
--format "pst", or maybe --format "tsp" to put the path last.
|
--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)
|
list.AddHash(hashType)
|
||||||
case 'i':
|
case 'i':
|
||||||
list.AddID()
|
list.AddID()
|
||||||
|
case 'm':
|
||||||
|
list.AddMimeType()
|
||||||
default:
|
default:
|
||||||
return errors.Errorf("Unknown format character %q", char)
|
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
|
// AppendOutput adds string generated by specific function to printed output
|
||||||
func (l *ListFormat) AppendOutput(functionToAppend func() string) {
|
func (l *ListFormat) AppendOutput(functionToAppend func() string) {
|
||||||
if len(l.output) > 0 {
|
if len(l.output) > 0 {
|
||||||
|
|
|
@ -716,6 +716,11 @@ func TestListFormat(t *testing.T) {
|
||||||
list.AddID()
|
list.AddID()
|
||||||
_ = operations.ListFormatted(&items[0], &list) // Can't really check anything - at least it didn't panic!
|
_ = 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.SetOutput(nil)
|
||||||
list.AddSize()
|
list.AddSize()
|
||||||
assert.Equal(t, "1", operations.ListFormatted(&items[0], &list))
|
assert.Equal(t, "1", operations.ListFormatted(&items[0], &list))
|
||||||
|
|
Loading…
Add table
Reference in a new issue