From aaeeaf658aef1a7baed6414723f2903eebffc704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20L=C3=B3pez?= Date: Wed, 9 Sep 2026 13:06:28 +0200 Subject: [PATCH 1/3] feat(cli): add --version flag and show version in the group help Register a top-level --version option on the CLI group and render "AFQuery v" in the group help header. The version is read from afquery.__version__ (populated by hatch-vcs from the release tag), so it needs no manual update per release. Drop the hand-maintained "Commands: ..." line from the group docstring; Click already generates a complete Commands section. --- src/afquery/cli.py | 19 ++++++++++++------- tests/test_cli.py | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/afquery/cli.py b/src/afquery/cli.py index dda602e..0c3561c 100644 --- a/src/afquery/cli.py +++ b/src/afquery/cli.py @@ -4,6 +4,8 @@ import click +from afquery import __version__ + from .database import Database @@ -168,15 +170,18 @@ def _print_carriers(carriers, variant_key, fmt: str) -> None: click.echo(fmt_row.format(*row)) -@click.group() -def cli(): - """AFQuery: bitmap-indexed allele frequency engine for local genomic cohorts. +_CLI_HELP = f"""\ +AFQuery v{__version__} — bitmap-indexed allele frequency engine for local genomic cohorts. - Enables fast AC/AN/AF queries on user-defined subcohorts (phenotype, sex, - technology) without rescanning VCFs. +Enables fast AC/AN/AF queries on user-defined subcohorts (phenotype, sex, +technology) without rescanning VCFs. +""" - Commands: query, variant-info, annotate, dump, info, version, create-db, update-db, check, benchmark - """ + +@click.group(help=_CLI_HELP) +@click.version_option(version=__version__, prog_name="afquery", message="%(prog)s %(version)s") +def cli(): + pass @cli.command() diff --git a/tests/test_cli.py b/tests/test_cli.py index 4251286..b89e982 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -375,6 +375,29 @@ def test_version_set_then_show(runner, db_copy): assert "MYVER" in result.output +# --- afquery --version / --help --- + +def test_version_flag(runner): + from afquery import __version__ + result = runner.invoke(cli, ["--version"]) + assert result.exit_code == 0 + assert __version__ in result.output + + +def test_help_shows_program_name_and_version(runner): + from afquery import __version__ + result = runner.invoke(cli, ["--help"]) + assert result.exit_code == 0 + assert f"AFQuery v{__version__}" in result.output + + +def test_help_lists_all_commands(runner): + result = runner.invoke(cli, ["--help"]) + for cmd in ("query", "variant-info", "annotate", "dump", "info", + "version", "create-db", "update-db", "check", "benchmark"): + assert cmd in result.output + + # --- afquery check --- def test_check_ok(runner, test_db): From 5f930d2f8100d0921a80a25d0881e56ae3e700d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20L=C3=B3pez?= Date: Wed, 9 Sep 2026 13:06:32 +0200 Subject: [PATCH 2/3] docs(cli): document the global --version option Add a "Global options" section to the CLI reference covering --version and --help. --- docs/reference/cli.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 9cb83f0..8c880e0 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -4,6 +4,18 @@ All AFQuery commands follow the pattern `afquery [OPTIONS]`. --- +## Global options + +| Option | Description | +|--------|-------------| +| `--version` | Print the installed AFQuery version and exit | +| `--help` | Show help for the command and exit | + +`afquery --version` prints e.g. `afquery 0.4.2`. The version is derived from the +release tag at build time. + +--- + ## create-db Build a new AFQuery database from a manifest of single-sample VCFs. From f34d2eac44aea6be422651cec7b34db458e8be09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20L=C3=B3pez?= Date: Wed, 9 Sep 2026 13:11:43 +0200 Subject: [PATCH 3/3] docs(cli): clarify what afquery --version reports --- docs/reference/cli.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 8c880e0..4f7d707 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -8,11 +8,12 @@ All AFQuery commands follow the pattern `afquery [OPTIONS]`. | Option | Description | |--------|-------------| -| `--version` | Print the installed AFQuery version and exit | +| `--version` | Print the AFQuery version and exit | | `--help` | Show help for the command and exit | -`afquery --version` prints e.g. `afquery 0.4.2`. The version is derived from the -release tag at build time. +`afquery --version` prints the installed package version (e.g. `afquery 0.4.2`), +taken from the Git release tag at build time. In an editable install +(`pip install -e .`) it reflects the last build, not later local commits. ---