mirror of
https://github.com/rclone/rclone.git
synced 2025-02-19 20:11:15 +01:00
lsjson: add --metadata/-M flag
Note that this removes the `-M` flag from `--encrypted` as it conflicted with the global flag and adds it to `--metadata`.
This commit is contained in:
parent
78d52882ca
commit
d823a38ce5
@ -26,10 +26,11 @@ func init() {
|
|||||||
flags.BoolVarP(cmdFlags, &opt.ShowHash, "hash", "", false, "Include hashes in the output (may take longer)")
|
flags.BoolVarP(cmdFlags, &opt.ShowHash, "hash", "", false, "Include hashes in the output (may take longer)")
|
||||||
flags.BoolVarP(cmdFlags, &opt.NoModTime, "no-modtime", "", false, "Don't read the modification time (can speed things up)")
|
flags.BoolVarP(cmdFlags, &opt.NoModTime, "no-modtime", "", false, "Don't read the modification time (can speed things up)")
|
||||||
flags.BoolVarP(cmdFlags, &opt.NoMimeType, "no-mimetype", "", false, "Don't read the mime type (can speed things up)")
|
flags.BoolVarP(cmdFlags, &opt.NoMimeType, "no-mimetype", "", false, "Don't read the mime type (can speed things up)")
|
||||||
flags.BoolVarP(cmdFlags, &opt.ShowEncrypted, "encrypted", "M", false, "Show the encrypted names")
|
flags.BoolVarP(cmdFlags, &opt.ShowEncrypted, "encrypted", "", false, "Show the encrypted names")
|
||||||
flags.BoolVarP(cmdFlags, &opt.ShowOrigIDs, "original", "", false, "Show the ID of the underlying Object")
|
flags.BoolVarP(cmdFlags, &opt.ShowOrigIDs, "original", "", false, "Show the ID of the underlying Object")
|
||||||
flags.BoolVarP(cmdFlags, &opt.FilesOnly, "files-only", "", false, "Show only files in the listing")
|
flags.BoolVarP(cmdFlags, &opt.FilesOnly, "files-only", "", false, "Show only files in the listing")
|
||||||
flags.BoolVarP(cmdFlags, &opt.DirsOnly, "dirs-only", "", false, "Show only directories in the listing")
|
flags.BoolVarP(cmdFlags, &opt.DirsOnly, "dirs-only", "", false, "Show only directories in the listing")
|
||||||
|
flags.BoolVarP(cmdFlags, &opt.Metadata, "metadata", "M", false, "Add metadata to the listing")
|
||||||
flags.StringArrayVarP(cmdFlags, &opt.HashTypes, "hash-type", "", nil, "Show only this hash type (may be repeated)")
|
flags.StringArrayVarP(cmdFlags, &opt.HashTypes, "hash-type", "", nil, "Show only this hash type (may be repeated)")
|
||||||
flags.BoolVarP(cmdFlags, &statOnly, "stat", "", false, "Just return the info for the pointed to file")
|
flags.BoolVarP(cmdFlags, &statOnly, "stat", "", false, "Just return the info for the pointed to file")
|
||||||
}
|
}
|
||||||
@ -81,6 +82,9 @@ returned
|
|||||||
If ` + "`--files-only`" + ` is not specified directories in addition to the files
|
If ` + "`--files-only`" + ` is not specified directories in addition to the files
|
||||||
will be returned.
|
will be returned.
|
||||||
|
|
||||||
|
If ` + "`--metadata`" + ` is set then an additional Metadata key will be returned.
|
||||||
|
This will have metdata in rclone standard format as a JSON object.
|
||||||
|
|
||||||
if ` + "`--stat`" + ` is set then a single JSON blob will be returned about the
|
if ` + "`--stat`" + ` is set then a single JSON blob will be returned about the
|
||||||
item pointed to. This will return an error if the item isn't found.
|
item pointed to. This will return an error if the item isn't found.
|
||||||
However on bucket based backends (like s3, gcs, b2, azureblob etc) if
|
However on bucket based backends (like s3, gcs, b2, azureblob etc) if
|
||||||
|
@ -29,6 +29,7 @@ type ListJSONItem struct {
|
|||||||
OrigID string `json:",omitempty"`
|
OrigID string `json:",omitempty"`
|
||||||
Tier string `json:",omitempty"`
|
Tier string `json:",omitempty"`
|
||||||
IsBucket bool `json:",omitempty"`
|
IsBucket bool `json:",omitempty"`
|
||||||
|
Metadata fs.Metadata `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timestamp a time in the provided format
|
// Timestamp a time in the provided format
|
||||||
@ -80,6 +81,7 @@ type ListJSONOpt struct {
|
|||||||
ShowHash bool `json:"showHash"`
|
ShowHash bool `json:"showHash"`
|
||||||
DirsOnly bool `json:"dirsOnly"`
|
DirsOnly bool `json:"dirsOnly"`
|
||||||
FilesOnly bool `json:"filesOnly"`
|
FilesOnly bool `json:"filesOnly"`
|
||||||
|
Metadata bool `json:"metadata"`
|
||||||
HashTypes []string `json:"hashTypes"` // hash types to show if ShowHash is set, e.g. "MD5", "SHA-1"
|
HashTypes []string `json:"hashTypes"` // hash types to show if ShowHash is set, e.g. "MD5", "SHA-1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,6 +224,14 @@ func (lj *listJSON) entry(ctx context.Context, entry fs.DirEntry) (*ListJSONItem
|
|||||||
item.Tier = do.GetTier()
|
item.Tier = do.GetTier()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if lj.opt.Metadata {
|
||||||
|
metadata, err := fs.GetMetadata(ctx, x)
|
||||||
|
if err != nil {
|
||||||
|
fs.Errorf(x, "Failed to read metadata: %v", err)
|
||||||
|
} else if metadata != nil {
|
||||||
|
item.Metadata = metadata
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
fs.Errorf(nil, "Unknown type %T in listing in ListJSON", entry)
|
fs.Errorf(nil, "Unknown type %T in listing in ListJSON", entry)
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,19 @@ func TestListJSON(t *testing.T) {
|
|||||||
ModTime: operations.Timestamp{When: t1},
|
ModTime: operations.Timestamp{When: t1},
|
||||||
IsDir: false,
|
IsDir: false,
|
||||||
}},
|
}},
|
||||||
|
}, {
|
||||||
|
name: "Metadata",
|
||||||
|
opt: operations.ListJSONOpt{
|
||||||
|
FilesOnly: true,
|
||||||
|
Metadata: true,
|
||||||
|
},
|
||||||
|
want: []*operations.ListJSONItem{{
|
||||||
|
Path: "file1",
|
||||||
|
Name: "file1",
|
||||||
|
Size: 5,
|
||||||
|
ModTime: operations.Timestamp{When: t1},
|
||||||
|
IsDir: false,
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
@ -34,6 +34,7 @@ func init() {
|
|||||||
- noMimeType - If set don't show mime types
|
- noMimeType - If set don't show mime types
|
||||||
- dirsOnly - If set only show directories
|
- dirsOnly - If set only show directories
|
||||||
- filesOnly - If set only show files
|
- filesOnly - If set only show files
|
||||||
|
- metadata - If set return metadata of objects also
|
||||||
- hashTypes - array of strings of hash types to show if showHash set
|
- hashTypes - array of strings of hash types to show if showHash set
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
Loading…
Reference in New Issue
Block a user