mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 01:06:50 +00:00
list: --json for archive listing
This commit is contained in:
parent
6180f5055c
commit
25781f53d4
1 changed files with 14 additions and 1 deletions
|
@ -977,8 +977,19 @@ def _list_repository(self, args, manifest, write):
|
|||
format = "{archive:<36} {time} [{id}]{NL}"
|
||||
formatter = ArchiveFormatter(format)
|
||||
|
||||
output_data = []
|
||||
|
||||
for archive_info in manifest.archives.list_considering(args):
|
||||
write(safe_encode(formatter.format_item(archive_info)))
|
||||
if args.json:
|
||||
output_data.append(formatter.get_item_data(archive_info))
|
||||
else:
|
||||
write(safe_encode(formatter.format_item(archive_info)))
|
||||
|
||||
if args.json:
|
||||
print_as_json({
|
||||
'repository': manifest.repository,
|
||||
'archives': output_data,
|
||||
})
|
||||
|
||||
return self.exit_code
|
||||
|
||||
|
@ -2492,6 +2503,8 @@ def process_epilog(epilog):
|
|||
subparser.add_argument('--format', '--list-format', dest='format', type=str,
|
||||
help="""specify format for file listing
|
||||
(default: "{mode} {user:6} {group:6} {size:8d} {isomtime} {path}{extra}{NL}")""")
|
||||
subparser.add_argument('--json', action='store_true',
|
||||
help='format output as JSON')
|
||||
subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='',
|
||||
type=location_validator(),
|
||||
help='repository/archive to list contents of')
|
||||
|
|
Loading…
Reference in a new issue