Browse Source

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

Dan Helfman 3 weeks ago
parent
commit
fd46efb193

+ 2
- 1
NEWS View File

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

+ 13
- 0
borgmatic/commands/borgmatic.py View File

@@ -5,6 +5,8 @@ import os
5 5
 from subprocess import CalledProcessError
6 6
 import sys
7 7
 
8
+import pkg_resources
9
+
8 10
 from borgmatic.borg import (
9 11
     check as borg_check,
10 12
     create as borg_create,
@@ -136,6 +138,13 @@ def parse_arguments(*arguments):
136 138
         default=0,
137 139
         help='Display verbose progress (1 for some, 2 for lots)',
138 140
     )
141
+    parser.add_argument(
142
+        '--version',
143
+        dest='version',
144
+        default=False,
145
+        action='store_true',
146
+        help='Display installed version number of borgmatic and exit',
147
+    )
139 148
 
140 149
     args = parser.parse_args(arguments)
141 150
 
@@ -346,6 +355,10 @@ def main():  # pragma: no cover
346 355
     args = parse_arguments(*sys.argv[1:])
347 356
     logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
348 357
 
358
+    if args.version:
359
+        print(pkg_resources.require('borgmatic')[0].version)
360
+        sys.exit(0)
361
+
349 362
     config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
350 363
     logger.debug('Ensuring legacy configuration is upgraded')
351 364
     convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)

+ 1
- 1
setup.py View File

@@ -1,7 +1,7 @@
1 1
 from setuptools import setup, find_packages
2 2
 
3 3
 
4
-VERSION = '1.2.14.dev0'
4
+VERSION = '1.2.14'
5 5
 
6 6
 
7 7
 setup(

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

@@ -1,3 +1,5 @@
1
+import subprocess
2
+
1 3
 from flexmock import flexmock
2 4
 import pytest
3 5
 
@@ -169,3 +171,10 @@ def test_parse_arguments_disallows_json_without_list_or_info():
169 171
 def test_parse_arguments_disallows_json_with_both_list_and_info():
170 172
     with pytest.raises(ValueError):
171 173
         module.parse_arguments('--list', '--info', '--json')
174
+
175
+
176
+def test_borgmatic_version_matches_news_version():
177
+    borgmatic_version = subprocess.check_output(('borgmatic', '--version')).decode('ascii')
178
+    news_version = open('NEWS').readline()
179
+
180
+    assert borgmatic_version == news_version

+ 0
- 8
tests/integration/test_version.py View File

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

Loading…
Cancel
Save