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
10 changes: 10 additions & 0 deletions src/tocode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import os
import sys
import time
from pathlib import Path

from .analysis import create_analyzer
Expand Down Expand Up @@ -102,6 +103,7 @@ def main(argv: list[str] | None = None) -> int:
args.out_dir = (
args.out_dir.expanduser().resolve() if args.out_dir is not None else None
)
started = time.monotonic()
try:
if not binary.is_file():
parser.error(f"input must be a regular file: {binary}")
Expand All @@ -115,9 +117,17 @@ def main(argv: list[str] | None = None) -> int:
f"Summary: functions={summary.function_count} "
f"clusters={summary.cluster_count} failures={len(summary.failed_functions)}"
)
print(f"Exported in {_format_duration(time.monotonic() - started)}")
return 0


def _format_duration(seconds: float) -> str:
if seconds >= 60:
minutes, secs = divmod(int(round(seconds)), 60)
return f"{minutes}m {secs}s"
return f"{seconds:.1f}s"


def _run_one(
binary: Path, *, args: argparse.Namespace, progress: Progress, out_dir: Path | None
):
Expand Down
8 changes: 7 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import pytest

from tocode.cli import build_parser, parse_jobs
from tocode.cli import _format_duration, build_parser, parse_jobs


def test_format_duration_uses_seconds_then_minutes() -> None:
assert _format_duration(4.27) == "4.3s"
assert _format_duration(75) == "1m 15s"
assert _format_duration(3600) == "60m 0s"


def test_parse_jobs_accepts_auto_and_positive_ints() -> None:
Expand Down
Loading