Browse Source

Add borgmatic --version command-line flag to get the current installed version number.

Dan Helfman 6 năm trước cách đây
mục cha
commit
fd46efb193

+ 2 - 1
NEWS

@@ -1,8 +1,9 @@
-1.2.14.dev0
+1.2.14
  * #103: When generating sample configuration with generate-borgmatic-config, document the defaults
    for each option.
  * #116: When running multiple configuration files, attempt all configuration files even if one of
    them errors. Log a summary of results at the end.
+ * Add borgmatic --version command-line flag to get the current installed version number.
 
 1.2.13
  * #100: Support for --stats command-line flag independent of --verbosity.

+ 13 - 0
borgmatic/commands/borgmatic.py

@@ -5,6 +5,8 @@ import os
 from subprocess import CalledProcessError
 import sys
 
+import pkg_resources
+
 from borgmatic.borg import (
     check as borg_check,
     create as borg_create,
@@ -136,6 +138,13 @@ def parse_arguments(*arguments):
         default=0,
         help='Display verbose progress (1 for some, 2 for lots)',
     )
+    parser.add_argument(
+        '--version',
+        dest='version',
+        default=False,
+        action='store_true',
+        help='Display installed version number of borgmatic and exit',
+    )
 
     args = parser.parse_args(arguments)
 
@@ -346,6 +355,10 @@ def main():  # pragma: no cover
     args = parse_arguments(*sys.argv[1:])
     logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
 
+    if args.version:
+        print(pkg_resources.require('borgmatic')[0].version)
+        sys.exit(0)
+
     config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
     logger.debug('Ensuring legacy configuration is upgraded')
     convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)

+ 1 - 1
setup.py

@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 
 
-VERSION = '1.2.14.dev0'
+VERSION = '1.2.14'
 
 
 setup(

+ 9 - 0
tests/integration/commands/test_borgmatic.py

@@ -1,3 +1,5 @@
+import subprocess
+
 from flexmock import flexmock
 import pytest
 
@@ -169,3 +171,10 @@ def test_parse_arguments_disallows_json_without_list_or_info():
 def test_parse_arguments_disallows_json_with_both_list_and_info():
     with pytest.raises(ValueError):
         module.parse_arguments('--list', '--info', '--json')
+
+
+def test_borgmatic_version_matches_news_version():
+    borgmatic_version = subprocess.check_output(('borgmatic', '--version')).decode('ascii')
+    news_version = open('NEWS').readline()
+
+    assert borgmatic_version == news_version

+ 0 - 8
tests/integration/test_version.py

@@ -1,8 +0,0 @@
-import subprocess
-
-
-def test_setup_version_matches_news_version():
-    setup_version = subprocess.check_output(('python', 'setup.py', '--version')).decode('ascii')
-    news_version = open('NEWS').readline()
-
-    assert setup_version == news_version