From d5dae8dfda1fb554d9209b3f1bf5af9cb72b3f07 Mon Sep 17 00:00:00 2001 From: Tom Schraitle Date: Wed, 14 Apr 2021 08:25:49 +0200 Subject: [PATCH] Fix #339: Provide a --version option * Create and adapt tests for `--version` * Add newsfragment Co-authored-by: Adi Roiban --- src/towncrier/_shell.py | 2 ++ src/towncrier/newsfragments/339.feature.rst | 1 + src/towncrier/test/test_project.py | 9 ++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/towncrier/newsfragments/339.feature.rst diff --git a/src/towncrier/_shell.py b/src/towncrier/_shell.py index 55be0607..e7f10f69 100644 --- a/src/towncrier/_shell.py +++ b/src/towncrier/_shell.py @@ -11,9 +11,11 @@ from .build import _main as _build_cmd from .check import _main as _check_cmd from .create import _main as _create_cmd +from ._version import __version__ @click.group(cls=DefaultGroup, default="build", default_if_no_args=True) +@click.version_option(__version__.public()) def cli(): pass diff --git a/src/towncrier/newsfragments/339.feature.rst b/src/towncrier/newsfragments/339.feature.rst new file mode 100644 index 00000000..79243cb4 --- /dev/null +++ b/src/towncrier/newsfragments/339.feature.rst @@ -0,0 +1 @@ +towncrier --version` was added to the command line interface to show the product version. diff --git a/src/towncrier/test/test_project.py b/src/towncrier/test/test_project.py index 01bdf0e0..db734f4e 100644 --- a/src/towncrier/test/test_project.py +++ b/src/towncrier/test/test_project.py @@ -116,6 +116,13 @@ def test_dash_m(self): os.makedirs("news") out = check_output([sys.executable, "-m", "towncrier", "--help"]) self.assertIn(b"[OPTIONS] COMMAND [ARGS]...", out) - self.assertIn(b"--help Show this message and exit.", out) + self.assertRegex(out, br".*--help\s+Show this message and exit.") finally: os.chdir(orig_dir) + + def test_version(self): + """ + `--version` command line option is available to show the current production version. + """ + out = check_output(["towncrier", "--version"]) + self.assertTrue(out.startswith(b"towncrier, version 2"))