1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 09:19:31 +00:00

list: --json for archive listing

This commit is contained in:
Marian Beermann 2017-02-23 12:32:26 +01:00
parent 6180f5055c
commit 25781f53d4

View file

@ -977,9 +977,20 @@ 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):
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
@with_repository(cache=True)
@ -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')