Skip to content

Commit f3b80e3

Browse files
tomwhitejeromekelleher
authored andcommitted
Add --version option to the cli
1 parent 7c32511 commit f3b80e3

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# auto generated by setuptools_scm and configured in pyproject.toml
2+
vcztools/_version.py
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]

tests/test_cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import vcztools.cli as cli
88
from tests.test_bcftools_validation import run_vcztools
99
from tests.utils import vcz_path_cache
10+
from vcztools import provenance
1011

1112

1213
@pytest.fixture()
@@ -184,3 +185,10 @@ def test_top_level():
184185
assert result.exit_code == 0
185186
assert len(result.stdout) > 0
186187
assert len(result.stderr) == 0
188+
189+
190+
def test_version():
191+
runner = ct.CliRunner(mix_stderr=False)
192+
result = runner.invoke(cli.vcztools_main, ["--version"], catch_exceptions=False)
193+
s = f"version {provenance.__version__}\n"
194+
assert result.stdout.endswith(s)

vcztools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .provenance import __version__ # noqa F401

vcztools/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import click
88

9-
from . import plink, vcf_writer
9+
from . import plink, provenance, vcf_writer
1010
from . import query as query_module
1111
from . import stats as stats_module
1212

@@ -60,6 +60,7 @@ def wrapper(*args, **kwargs):
6060
default="-",
6161
help="File path to write output to (defaults to stdout '-').",
6262
)
63+
version = click.version_option(version=f"{provenance.__version__}")
6364

6465

6566
class NaturalOrderGroup(click.Group):
@@ -278,6 +279,7 @@ def view_plink1(path, include, exclude, out):
278279
writer.run()
279280

280281

282+
@version
281283
@click.group(cls=NaturalOrderGroup, name="vcztools")
282284
def vcztools_main():
283285
pass

vcztools/provenance.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__version__ = "undefined"
2+
try:
3+
from . import _version
4+
5+
__version__ = _version.version
6+
except ImportError: # pragma: nocover
7+
pass

0 commit comments

Comments
 (0)