mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
lsf: add metadata support with M
flag
This commit is contained in:
parent
d823a38ce5
commit
776a083892
@ -72,6 +72,7 @@ output:
|
|||||||
m - MimeType of object if known
|
m - MimeType of object if known
|
||||||
e - encrypted name
|
e - encrypted name
|
||||||
T - tier of storage if known, e.g. "Hot" or "Cool"
|
T - tier of storage if known, e.g. "Hot" or "Cool"
|
||||||
|
M - Metadata of object in JSON blob format, eg {"key":"value"}
|
||||||
|
|
||||||
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.
|
||||||
@ -198,6 +199,9 @@ func Lsf(ctx context.Context, fsrc fs.Fs, out io.Writer) error {
|
|||||||
opt.ShowOrigIDs = true
|
opt.ShowOrigIDs = true
|
||||||
case 'T':
|
case 'T':
|
||||||
list.AddTier()
|
list.AddTier()
|
||||||
|
case 'M':
|
||||||
|
list.AddMetadata()
|
||||||
|
opt.Metadata = true
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown format character %q", char)
|
return fmt.Errorf("unknown format character %q", char)
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -2154,6 +2155,21 @@ func (l *ListFormat) AddMimeType() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddMetadata adds file's Metadata to the output if known
|
||||||
|
func (l *ListFormat) AddMetadata() {
|
||||||
|
l.AppendOutput(func(entry *ListJSONItem) string {
|
||||||
|
metadata := entry.Metadata
|
||||||
|
if metadata == nil {
|
||||||
|
metadata = make(fs.Metadata)
|
||||||
|
}
|
||||||
|
out, err := json.Marshal(metadata)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Sprintf("Failed to read metadata: %v", err.Error())
|
||||||
|
}
|
||||||
|
return string(out)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 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(item *ListJSONItem) string) {
|
func (l *ListFormat) AppendOutput(functionToAppend func(item *ListJSONItem) string) {
|
||||||
l.output = append(l.output, functionToAppend)
|
l.output = append(l.output, functionToAppend)
|
||||||
|
@ -1428,6 +1428,11 @@ func TestListFormat(t *testing.T) {
|
|||||||
assert.Contains(t, list.Format(item0), "/")
|
assert.Contains(t, list.Format(item0), "/")
|
||||||
assert.Equal(t, "inode/directory", list.Format(item1))
|
assert.Equal(t, "inode/directory", list.Format(item1))
|
||||||
|
|
||||||
|
list.SetOutput(nil)
|
||||||
|
list.AddMetadata()
|
||||||
|
assert.Equal(t, "{}", list.Format(item0))
|
||||||
|
assert.Equal(t, "{}", list.Format(item1))
|
||||||
|
|
||||||
list.SetOutput(nil)
|
list.SetOutput(nil)
|
||||||
list.AddPath()
|
list.AddPath()
|
||||||
list.SetAbsolute(true)
|
list.SetAbsolute(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user