소스 검색

Merge override values when specifying the "--override" flag multiple times (#361).

Dan Helfman 4 년 전
부모
커밋
1ea04aedf0
3개의 변경된 파일32개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      NEWS
  2. 1 0
      borgmatic/commands/arguments.py
  3. 29 0
      tests/integration/commands/test_arguments.py

+ 2 - 0
NEWS

@@ -2,6 +2,8 @@
  * #341: Add "temporary_directory" option for changing Borg's temporary directory.
  * #341: Add "temporary_directory" option for changing Borg's temporary directory.
  * #352: Lock down systemd security settings in sample systemd service file.
  * #352: Lock down systemd security settings in sample systemd service file.
  * #355: Fix traceback when a database hook value is null in a configuration file.
  * #355: Fix traceback when a database hook value is null in a configuration file.
+ * #361: Merge override values when specifying the "--override" flag multiple times. The previous
+   behavior was to take the value of the last "--override" flag only.
 
 
 1.5.10
 1.5.10
  * #347: Add hooks that run for the "extract" action: "before_extract" and "after_extract".
  * #347: Add hooks that run for the "extract" action: "before_extract" and "after_extract".

+ 1 - 0
borgmatic/commands/arguments.py

@@ -178,6 +178,7 @@ def parse_arguments(*unparsed_arguments):
         metavar='SECTION.OPTION=VALUE',
         metavar='SECTION.OPTION=VALUE',
         nargs='+',
         nargs='+',
         dest='overrides',
         dest='overrides',
+        action='extend',
         help='One or more configuration file options to override with specified values',
         help='One or more configuration file options to override with specified values',
     )
     )
     global_group.add_argument(
     global_group.add_argument(

+ 29 - 0
tests/integration/commands/test_arguments.py

@@ -71,6 +71,35 @@ def test_parse_arguments_with_log_file_verbosity_overrides_default():
     assert global_arguments.log_file_verbosity == -1
     assert global_arguments.log_file_verbosity == -1
 
 
 
 
+def test_parse_arguments_with_single_override_parses():
+    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
+
+    arguments = module.parse_arguments('--override', 'foo.bar=baz')
+
+    global_arguments = arguments['global']
+    assert global_arguments.overrides == ['foo.bar=baz']
+
+
+def test_parse_arguments_with_multiple_overrides_parses():
+    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
+
+    arguments = module.parse_arguments('--override', 'foo.bar=baz', 'foo.quux=7')
+
+    global_arguments = arguments['global']
+    assert global_arguments.overrides == ['foo.bar=baz', 'foo.quux=7']
+
+
+def test_parse_arguments_with_multiple_overrides_and_flags_parses():
+    flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
+
+    arguments = module.parse_arguments(
+        '--override', 'foo.bar=baz', '--override', 'foo.quux=7', 'this.that=8'
+    )
+
+    global_arguments = arguments['global']
+    assert global_arguments.overrides == ['foo.bar=baz', 'foo.quux=7', 'this.that=8']
+
+
 def test_parse_arguments_with_list_json_overrides_default():
 def test_parse_arguments_with_list_json_overrides_default():
     arguments = module.parse_arguments('list', '--json')
     arguments = module.parse_arguments('list', '--json')