Skip to content
Merged
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
9 changes: 9 additions & 0 deletions docs/docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ oracletrace <target> [--json OUTPUT.json] [--csv OUTPUT.csv] [--compare BASELINE
oracletrace <target> [--ignore REGEX [REGEX ...]]
oracletrace <target> [--top NUMBER]
oracletrace <target> [--compare BASELINE.json] [--fail-on-regression] [--threshold PERCENT] [--only-regressions]
oracletrace --version
```

## Required argument
Expand Down Expand Up @@ -117,6 +118,14 @@ Limit the summary table output to a maximum number of results.
oracletrace my_app.py --top 10
```

### `--version`

Prints version information and exit with a zero code.

```bash
oracletrace --version
```

## Exit behavior

OracleTrace returns a non-zero exit code when:
Expand Down
10 changes: 10 additions & 0 deletions oracletrace/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
from argparse import ArgumentParser, Namespace
from pathlib import Path
from dataclasses import asdict
from importlib.metadata import version


def main() -> int:
module_name = __name__.split(".")[0]
parser: ArgumentParser = ArgumentParser(
prog=module_name,
description="OracleTrace - Lightweight execution tracer for Python projects"
)
parser.add_argument("target", help="Python script to trace")
Expand Down Expand Up @@ -48,6 +51,13 @@ def main() -> int:
action="store_true",
help="Hide functions which didn't run slower than baseline. Use with --compare"
)

parser.add_argument(
"--version",
action="version",
help="Print version information then exit with a zero code",
version=f"%(prog)s {version(module_name)}"
)
args: Namespace = parser.parse_args()

target: str = args.target
Expand Down
9 changes: 9 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,12 @@ def test_main_shows_only_regressions(monkeypatch, tmp_path, trace_data, baseline
assert f" total_time: {baseline_trace_data.functions[0].total_time:.4f}s → {trace_data.functions[0].total_time:.4f}s" in captured.out
assert f"(+{102.2:.2f}%)\n" in captured.out
assert f"{trace_data.functions[1].name}\n" not in captured.out

def test_main_prints_version_exits_0(monkeypatch, trace_data, capsys):
module_name = "oracletrace"
with pytest.raises(SystemExit):
exit_code = _run_cli(monkeypatch,["oracletrace","--version",])

captured = capsys.readouterr()
assert exit_code == 0
assert f"{module_name} {importlib.metadata.version(module_name)}" in captured.out