From f913579402154a029d5d424c919a34bbdd073374 Mon Sep 17 00:00:00 2001 From: aga Date: Fri, 17 Apr 2026 13:04:27 +0200 Subject: [PATCH] Add CLI version flag --- CHANGELOG.md | 9 +++++++++ README.md | 6 ++++++ pyproject.toml | 2 +- src/photo_tools/cli.py | 14 ++++++++++++-- src/photo_tools/cli_support/cli_version.py | 18 ++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/photo_tools/cli_support/cli_version.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 36947d4..7bfcb4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog + +## [0.3.1] - 2026-04-17 + +### Added +- CLI `--version` flag + +### Documentation +- Documented `--version` usage in README + ## [0.3.0] - 2026-04-17 ### Added diff --git a/README.md b/README.md index 3e0e3d5..96e901f 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,12 @@ pipx install photo-tools-cli ``` Installs the CLI in an isolated environment and makes `photo-tools` available globally, avoiding dependency conflicts. +Check installed version: + +```shell +photo-tools --version +``` + ### Using pip (if pipx not available) ```shell diff --git a/pyproject.toml b/pyproject.toml index 3bc36bf..f5a9699 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "photo-tools-cli" -version = "0.3.0" +version = "0.3.1" description = "Python CLI tools for photography workflows" readme = "README.md" requires-python = ">=3.13" diff --git a/src/photo_tools/cli.py b/src/photo_tools/cli.py index 0f0ea2c..7571f20 100644 --- a/src/photo_tools/cli.py +++ b/src/photo_tools/cli.py @@ -3,6 +3,7 @@ from photo_tools.cli_support.cli_errors import handle_cli_errors from photo_tools.cli_support.cli_reporter import make_reporter +from photo_tools.cli_support.cli_version import version_callback from photo_tools.commands.clean_unpaired_raws import clean_unpaired_raws from photo_tools.commands.keep_five_star_raws import keep_five_star_raws from photo_tools.commands.optimise import optimise @@ -20,9 +21,18 @@ @app.callback() -def main() -> None: +def main( + version: bool = typer.Option( + None, + "--version", + "-V", + help="Show version and exit", + callback=version_callback, + is_eager=True, + ), +) -> None: try: - # validate dependencies needed globally (if any) + # validate dependencies needed globally validate_feature("exif") except MissingDependencyError as e: typer.secho(f"Error: {e}", fg=typer.colors.RED, err=True) diff --git a/src/photo_tools/cli_support/cli_version.py b/src/photo_tools/cli_support/cli_version.py new file mode 100644 index 0000000..7ce4308 --- /dev/null +++ b/src/photo_tools/cli_support/cli_version.py @@ -0,0 +1,18 @@ +from importlib.metadata import PackageNotFoundError, version + +import typer + + +def get_version() -> str: + try: + return version("photo-tools-cli") + except PackageNotFoundError: + return "unknown" + + +def version_callback(value: bool) -> None: + if not value: + return + + typer.echo(get_version()) + raise typer.Exit()