소스 검색

In "borgmatic --help", don't expand $HOME in listing of default "--config" paths.

Dan Helfman 5 년 전
부모
커밋
d0c533555e
5개의 변경된 파일21개의 추가작업 그리고 7개의 파일을 삭제
  1. 3 0
      NEWS
  2. 3 2
      borgmatic/commands/arguments.py
  3. 6 4
      borgmatic/config/collect.py
  4. 1 1
      setup.py
  5. 8 0
      tests/unit/config/test_collect.py

+ 3 - 0
NEWS

@@ -1,3 +1,6 @@
+1.4.22.dev0
+ * In "borgmatic --help", don't expand $HOME in listing of default "--config" paths.
+
 1.4.21
  * #268: Override particular configuration options from the command-line via "--override" flag. See
    the documentation for more information:

+ 3 - 2
borgmatic/commands/arguments.py

@@ -106,7 +106,8 @@ def parse_arguments(*unparsed_arguments):
     Given command-line arguments with which this script was invoked, parse the arguments and return
     them as a dict mapping from subparser name (or "global") to an argparse.Namespace instance.
     '''
-    config_paths = collect.get_default_config_paths()
+    config_paths = collect.get_default_config_paths(expand_home=True)
+    unexpanded_config_paths = collect.get_default_config_paths(expand_home=False)
 
     global_parser = ArgumentParser(add_help=False)
     global_group = global_parser.add_argument_group('global arguments')
@@ -118,7 +119,7 @@ def parse_arguments(*unparsed_arguments):
         dest='config_paths',
         default=config_paths,
         help='Configuration filenames or directories, defaults to: {}'.format(
-            ' '.join(config_paths)
+            ' '.join(unexpanded_config_paths)
         ),
     )
     global_group.add_argument(

+ 6 - 4
borgmatic/config/collect.py

@@ -1,15 +1,17 @@
 import os
 
 
-def get_default_config_paths():
+def get_default_config_paths(expand_home=True):
     '''
     Based on the value of the XDG_CONFIG_HOME and HOME environment variables, return a list of
     default configuration paths. This includes both system-wide configuration and configuration in
     the current user's home directory.
+
+    Don't expand the home directory ($HOME) if the expand home flag is False.
     '''
-    user_config_directory = os.getenv('XDG_CONFIG_HOME') or os.path.expandvars(
-        os.path.join('$HOME', '.config')
-    )
+    user_config_directory = os.getenv('XDG_CONFIG_HOME') or os.path.join('$HOME', '.config')
+    if expand_home:
+        user_config_directory = os.path.expandvars(user_config_directory)
 
     return [
         '/etc/borgmatic/config.yaml',

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 
-VERSION = '1.4.21'
+VERSION = '1.4.22.dev0'
 
 
 setup(

+ 8 - 0
tests/unit/config/test_collect.py

@@ -21,6 +21,14 @@ def test_get_default_config_paths_prefers_xdg_config_home_for_user_config_path()
     assert '/home/user/.etc/borgmatic/config.yaml' in config_paths
 
 
+def test_get_default_config_paths_does_not_expand_home_when_false():
+    flexmock(module.os, environ={'HOME': '/home/user'})
+
+    config_paths = module.get_default_config_paths(expand_home=False)
+
+    assert '$HOME/.config/borgmatic/config.yaml' in config_paths
+
+
 def test_collect_config_filenames_collects_given_files():
     config_paths = ('config.yaml', 'other.yaml')
     flexmock(module.os.path).should_receive('isdir').and_return(False)