Skip to content

Commit a95b471

Browse files
authored
Add version subcommand (#29)
2 parents ffafdfc + 1f87664 commit a95b471

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/blurb/blurb.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,13 @@ def get_subcommand(subcommand):
742742

743743

744744

745+
@subcommand
746+
def version():
747+
"""Print blurb version."""
748+
print("blurb version", __version__)
749+
750+
751+
745752
@subcommand
746753
def help(subcommand=None):
747754
"""
@@ -816,8 +823,10 @@ def help(subcommand=None):
816823
print(doc)
817824
sys.exit(0)
818825

819-
# Make "blurb --help" work.
826+
# Make "blurb --help/--version/-V" work.
820827
subcommands["--help"] = help
828+
subcommands["--version"] = version
829+
subcommands["-V"] = version
821830

822831

823832
def _find_blurb_dir():
@@ -1215,7 +1224,7 @@ def main():
12151224
fn = get_subcommand(subcommand)
12161225

12171226
# hack
1218-
if fn in (test, help):
1227+
if fn in (help, test, version):
12191228
sys.exit(fn(*args))
12201229

12211230
try:

tests/test_blurb.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,12 @@ def test_extract_next_filename(news_entry, expected_path, fs):
179179

180180
# Assert
181181
assert path == expected_path
182+
183+
184+
def test_version(capfd):
185+
# Act
186+
blurb.version()
187+
188+
# Assert
189+
captured = capfd.readouterr()
190+
assert captured.out.startswith("blurb version ")

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ commands =
1919
{posargs}
2020
blurb test
2121
blurb help
22+
blurb --version
2223
{envpython} -I -m blurb test
2324
{envpython} -I -m blurb help
25+
{envpython} -I -m blurb version

0 commit comments

Comments
 (0)