Disallow borg list --json with --archive or --find (#557).

This commit is contained in:
Dan Helfman 2022-08-15 15:40:28 -07:00
parent cc04bf57df
commit 7626fe1189
3 changed files with 17 additions and 30 deletions

View file

@ -117,7 +117,12 @@ def list_archive(
for flag_name in ('prefix', 'glob-archives', 'sort-by', 'first', 'last'): for flag_name in ('prefix', 'glob-archives', 'sort-by', 'first', 'last'):
if getattr(list_arguments, flag_name.replace('-', '_'), None): if getattr(list_arguments, flag_name.replace('-', '_'), None):
raise ValueError( raise ValueError(
f'The --{flag_name} flag on the list action is not supported when using the --archive flag and Borg 2.x.' f'The --{flag_name} flag on the list action is not supported when using the --archive/--find flags and Borg 2.x.'
)
if list_arguments.json:
raise ValueError(
'The --json flag on the list action is not supported when using the --archive/--find flags.'
) )
borg_environment = environment.make_environment(storage_config) borg_environment = environment.make_environment(storage_config)
@ -173,12 +178,9 @@ def list_archive(
remote_path, remote_path,
) + make_find_paths(list_arguments.find_paths) ) + make_find_paths(list_arguments.find_paths)
output = execute_command( execute_command(
main_command, main_command,
output_log_level=None if list_arguments.json else logging.WARNING, output_log_level=logging.WARNING,
borg_local_path=local_path, borg_local_path=local_path,
extra_environment=borg_environment, extra_environment=borg_environment,
) )
if list_arguments.json:
return output

View file

@ -626,7 +626,7 @@ def make_parsers():
'--successful', '--successful',
default=True, default=True,
action='store_true', action='store_true',
help='Deprecated; no effect. Newer versions of Borg list successful (non-checkpoint) archives by default.', help='Deprecated; no effect. Newer versions of Borg shows successful (non-checkpoint) archives by default.',
) )
list_group.add_argument( list_group.add_argument(
'--sort-by', metavar='KEYS', help='Comma-separated list of sorting keys' '--sort-by', metavar='KEYS', help='Comma-separated list of sorting keys'

View file

@ -282,27 +282,12 @@ def test_list_archive_calls_borg_with_parameters():
) )
def test_list_archive_with_json_suppresses_most_borg_output(): def test_list_archive_with_archive_and_json_errors():
list_arguments = argparse.Namespace(archive='archive', paths=None, json=True, find_paths=None) list_arguments = argparse.Namespace(archive='archive', paths=None, json=True, find_paths=None)
flexmock(module.feature).should_receive('available').and_return(False) flexmock(module.feature).should_receive('available').and_return(False)
flexmock(module).should_receive('make_list_command').with_args(
repository='repo',
storage_config={},
local_borg_version='1.2.3',
list_arguments=list_arguments,
local_path='borg',
remote_path=None,
).and_return(('borg', 'list', 'repo::archive'))
flexmock(module).should_receive('make_find_paths').and_return(())
flexmock(module.environment).should_receive('make_environment')
flexmock(module).should_receive('execute_command').with_args(
('borg', 'list', 'repo::archive'),
output_log_level=None,
borg_local_path='borg',
extra_environment=None,
).once()
with pytest.raises(ValueError):
module.list_archive( module.list_archive(
repository='repo', repository='repo',
storage_config={}, storage_config={},