Skip to content

Commit 0538b6c

Browse files
author
Arturo R Montesinos
committed
feat: add odsview CLI skeleton and tests
1 parent 26aa5ae commit 0538b6c

4 files changed

Lines changed: 105 additions & 0 deletions

File tree

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ exclude = ["^docs/curation/"]
1111
[build-system]
1212
requires = ["setuptools>=68", "wheel"]
1313
build-backend = "setuptools.build_meta"
14+
15+
[project]
16+
name = "odsview-cli-python"
17+
version = "0.0.1"
18+
description = "Read-only terminal viewer for .ods (LibreOffice Calc) files"
19+
requires-python = ">=3.9"
20+
dependencies = []
21+
22+
[project.scripts]
23+
odsview = "odsview.cli:main"

src/odsview/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""odsview package init.
2+
3+
For now, this only exposes the package version when defined.
4+
"""
5+
6+
__all__ = []

src/odsview/cli.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""CLI entry point for odsview.
2+
3+
This is a minimal placeholder implementing only ``--help`` for now.
4+
"""
5+
6+
from __future__ import annotations
7+
8+
import argparse
9+
import sys
10+
from typing import Sequence
11+
12+
13+
def build_parser() -> argparse.ArgumentParser:
14+
parser = argparse.ArgumentParser(
15+
prog="odsview",
16+
description=(
17+
"Read-only terminal viewer for .ods (LibreOffice Calc) files. "
18+
"Currently, only basic skeleton functionality is implemented."
19+
),
20+
)
21+
parser.add_argument(
22+
"file",
23+
nargs="?",
24+
help="Path to the .ods file to view (not yet implemented)",
25+
)
26+
return parser
27+
28+
29+
def main(argv: Sequence[str] | None = None) -> int:
30+
"""Entry point for the odsview CLI.
31+
32+
For now, this function only parses arguments and prints help when
33+
called without a file. Real functionality (loading and rendering
34+
.ods workbooks) will be added in future milestones.
35+
"""
36+
37+
if argv is None:
38+
argv = sys.argv[1:]
39+
40+
parser = build_parser()
41+
args = parser.parse_args(argv)
42+
43+
if args.file is None:
44+
# For now, just print help and exit with code 0.
45+
parser.print_help(sys.stdout)
46+
return 0
47+
48+
# Placeholder for future implementation.
49+
parser.error("viewing .ods files is not implemented yet")
50+
return 2
51+
52+
53+
if __name__ == "__main__": # pragma: no cover
54+
raise SystemExit(main())

tests/test_cli.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Smoke tests for the odsview CLI skeleton."""
2+
3+
from __future__ import annotations
4+
5+
import os
6+
import subprocess
7+
import sys
8+
from pathlib import Path
9+
10+
11+
def run_cli(*args: str) -> subprocess.CompletedProcess[str]:
12+
project_root = Path(__file__).resolve().parents[1]
13+
env = dict(**os.environ)
14+
# Ensure the package can be imported via the project root on sys.path.
15+
env.setdefault("PYTHONPATH", str(project_root / "src"))
16+
return subprocess.run(
17+
[sys.executable, "-m", "odsview.cli", *args],
18+
cwd=project_root,
19+
text=True,
20+
capture_output=True,
21+
env=env,
22+
check=False,
23+
)
24+
25+
26+
def test_help_exits_zero() -> None:
27+
result = run_cli("--help")
28+
assert result.returncode == 0
29+
assert "usage:" in result.stdout.lower()
30+
31+
32+
def test_no_args_prints_help_and_exits_zero() -> None:
33+
result = run_cli()
34+
assert result.returncode == 0
35+
assert "usage:" in result.stdout.lower()

0 commit comments

Comments
 (0)