diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index c2ebbd885..0cdb33576 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -513,7 +513,12 @@ def add_arguments_from_schema(arguments_group, schema, unparsed_arguments, names default=None, help=description, ) - no_flag_name = '.'.join(names[:-1] + ('no-' + names[-1],)).replace('_', '-') + + if names[-1].startswith('no_'): + no_flag_name = '.'.join(names[:-1] + (names[-1][len('no_') :],)).replace('_', '-') + else: + no_flag_name = '.'.join(names[:-1] + ('no-' + names[-1],)).replace('_', '-') + arguments_group.add_argument( f'--{no_flag_name}', dest=flag_name.replace('-', '_'), diff --git a/tests/unit/commands/test_arguments.py b/tests/unit/commands/test_arguments.py index efc437b35..f30942772 100644 --- a/tests/unit/commands/test_arguments.py +++ b/tests/unit/commands/test_arguments.py @@ -1235,6 +1235,39 @@ def test_add_arguments_from_schema_with_nested_boolean_adds_two_valueless_flags( ) +def test_add_arguments_from_schema_with_boolean_with_name_prefixed_with_no_adds_two_valueless_flags_and_removes_the_no_for_one(): + arguments_group = flexmock() + flexmock(module).should_receive('make_argument_description').and_return('help') + flexmock(module.borgmatic.config.schema).should_receive('parse_type').and_return(bool) + arguments_group.should_receive('add_argument').with_args( + '--no-foo', + action='store_true', + default=None, + help='help', + ).once() + arguments_group.should_receive('add_argument').with_args( + '--foo', + dest='no_foo', + action='store_false', + default=None, + help=object, + ).once() + flexmock(module).should_receive('add_array_element_arguments') + + module.add_arguments_from_schema( + arguments_group=arguments_group, + schema={ + 'type': 'object', + 'properties': { + 'no_foo': { + 'type': 'boolean', + } + }, + }, + unparsed_arguments=(), + ) + + def test_add_arguments_from_schema_skips_omitted_flag_name(): arguments_group = flexmock() flexmock(module).should_receive('make_argument_description').and_return('help')