diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index 4930bb4..faefd10 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -742,6 +742,13 @@ def get_subcommand(subcommand): +@subcommand +def version(): + """Print blurb version.""" + print("blurb version", __version__) + + + @subcommand def help(subcommand=None): """ @@ -816,8 +823,10 @@ def help(subcommand=None): print(doc) sys.exit(0) -# Make "blurb --help" work. +# Make "blurb --help/--version/-V" work. subcommands["--help"] = help +subcommands["--version"] = version +subcommands["-V"] = version @subcommand @@ -1205,7 +1214,7 @@ def main(): fn = get_subcommand(subcommand) # hack - if fn in (test, help): + if fn in (help, test, version): sys.exit(fn(*args)) try: diff --git a/tests/test_blurb.py b/tests/test_blurb.py index 1c18a9f..9ff3a8d 100644 --- a/tests/test_blurb.py +++ b/tests/test_blurb.py @@ -179,3 +179,12 @@ def test_extract_next_filename(news_entry, expected_path, fs): # Assert assert path == expected_path + + +def test_version(capfd): + # Act + blurb.version() + + # Assert + captured = capfd.readouterr() + assert captured.out.startswith("blurb version ") diff --git a/tox.ini b/tox.ini index 4956937..fa69718 100644 --- a/tox.ini +++ b/tox.ini @@ -19,5 +19,7 @@ commands = {posargs} blurb test blurb help + blurb --version {envpython} -I -m blurb test {envpython} -I -m blurb help + {envpython} -I -m blurb version