Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sqlit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
27 changes: 26 additions & 1 deletion tests/cli/test_cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""),
},
)


Expand Down Expand Up @@ -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
Loading