diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 9cb83f0..4f7d707 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -4,6 +4,19 @@ All AFQuery commands follow the pattern `afquery [OPTIONS]`. --- +## Global options + +| Option | Description | +|--------|-------------| +| `--version` | Print the AFQuery version and exit | +| `--help` | Show help for the command and exit | + +`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. + +--- + ## create-db Build a new AFQuery database from a manifest of single-sample VCFs. 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):