diff --git a/NEWS b/NEWS index a7ba0082..c8b52cd6 100644 --- a/NEWS +++ b/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. diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index ae430563..6d1080ad 100644 --- a/borgmatic/commands/borgmatic.py +++ b/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) diff --git a/setup.py b/setup.py index 9a38bb4c..bf7d499a 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages -VERSION = '1.2.14.dev0' +VERSION = '1.2.14' setup( diff --git a/tests/integration/commands/test_borgmatic.py b/tests/integration/commands/test_borgmatic.py index d50a30dc..0dee6e2b 100644 --- a/tests/integration/commands/test_borgmatic.py +++ b/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 diff --git a/tests/integration/test_version.py b/tests/integration/test_version.py deleted file mode 100644 index e5ba4861..00000000 --- a/tests/integration/test_version.py +++ /dev/null @@ -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