From 97049c2b358dd57529a30ada92851e28886b1ab7 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:52:45 +0300 Subject: [PATCH 1/3] Add version subcommand --- src/blurb/blurb.py | 13 ++++++++++++- tox.ini | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index 4930bb4..27c3e3d 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -742,6 +742,15 @@ def get_subcommand(subcommand): +@subcommand +def version(): + """ +Print blurb version. + """ + print("blurb version", __version__) + + + @subcommand def help(subcommand=None): """ @@ -818,6 +827,8 @@ def help(subcommand=None): # Make "blurb --help" work. subcommands["--help"] = help +subcommands["--version"] = version +subcommands["-v"] = version @subcommand @@ -1205,7 +1216,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/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 From 56bba411e210b94b5a485c5300856adfbe623fca Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:53:17 +0300 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Ezio Melotti Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- src/blurb/blurb.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index 27c3e3d..faefd10 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -744,9 +744,7 @@ def get_subcommand(subcommand): @subcommand def version(): - """ -Print blurb version. - """ + """Print blurb version.""" print("blurb version", __version__) @@ -825,10 +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 +subcommands["-V"] = version @subcommand From 1f876646a7cb6765475f30454fe6fc01ae5014db Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 20:00:13 +0300 Subject: [PATCH 3/3] Test version() --- tests/test_blurb.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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 ")