From 33b16c4dcd63f98b4668b9ab040e6eb91e9cbe24 Mon Sep 17 00:00:00 2001 From: Peter Adams <18162810+Maxteabag@users.noreply.github.com> Date: Thu, 4 Jun 2026 11:27:24 +0200 Subject: [PATCH] feat: add -v and --version CLI options --- sqlit/cli.py | 7 +++++++ tests/cli/test_cli_main.py | 27 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/sqlit/cli.py b/sqlit/cli.py index f5b838f..a85487c 100644 --- a/sqlit/cli.py +++ b/sqlit/cli.py @@ -490,6 +490,7 @@ def main() -> int: connection_url, filtered_argv = _extract_connection_url(filtered_argv) log_startup_step("cli_parser_start") + from sqlit import __version__ parser = argparse.ArgumentParser( prog="sqlit", description="A terminal UI for SQL databases", @@ -502,6 +503,12 @@ def main() -> int: ), formatter_class=argparse.RawDescriptionHelpFormatter, ) + parser.add_argument( + "-v", + "--version", + action="version", + version=f"%(prog)s {__version__}", + ) parser.add_argument( "--mock", diff --git a/tests/cli/test_cli_main.py b/tests/cli/test_cli_main.py index ba32736..b3e0acb 100644 --- a/tests/cli/test_cli_main.py +++ b/tests/cli/test_cli_main.py @@ -15,7 +15,12 @@ def _run_cli_with_stdin(*args: str, stdin: str, env_config_dir: Path) -> subproc input=stdin, capture_output=True, text=True, - env={"SQLIT_CONFIG_DIR": str(env_config_dir), "PATH": __import__("os").environ.get("PATH", "")}, + cwd=str(env_config_dir), + env={ + "SQLIT_CONFIG_DIR": str(env_config_dir), + "PATH": __import__("os").environ.get("PATH", ""), + "PYTHONPATH": __import__("os").environ.get("PYTHONPATH", ""), + }, ) @@ -118,3 +123,23 @@ def test_password_stdin_eof_errors_cleanly(tmp_path: Path): assert result.returncode != 0 assert "EOF" in (result.stderr + result.stdout) + + +def test_cli_version_option(tmp_path: Path): + result = _run_cli_with_stdin( + "--version", + stdin="", + env_config_dir=tmp_path, + ) + assert result.returncode == 0 + assert "sqlit" in result.stdout + + +def test_cli_version_short_option(tmp_path: Path): + result = _run_cli_with_stdin( + "-v", + stdin="", + env_config_dir=tmp_path, + ) + assert result.returncode == 0 + assert "sqlit" in result.stdout