Skip to content

Commit

Permalink
Add version subcommand (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Oct 12, 2024
2 parents ffafdfc + 1f87664 commit a95b471
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/blurb/blurb.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,13 @@ def get_subcommand(subcommand):



@subcommand
def version():
"""Print blurb version."""
print("blurb version", __version__)



@subcommand
def help(subcommand=None):
"""
Expand Down Expand Up @@ -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


def _find_blurb_dir():
Expand Down Expand Up @@ -1215,7 +1224,7 @@ def main():
fn = get_subcommand(subcommand)

# hack
if fn in (test, help):
if fn in (help, test, version):
sys.exit(fn(*args))

try:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_blurb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a95b471

Please sign in to comment.