Skip to content
Closed
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
15 changes: 14 additions & 1 deletion cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,56 @@ python -m cli.cli --help
## Commands

### Hello Command

```bash
linux-cli hello greet
linux-cli hello greet "Linux User"
```

### Build Command

```bash
linux-cli build
```

## Development

### Running Tests

```bash
pytest
```

### Code Formatting

```bash
black cli/
```

### Import Sorting

```bash
isort cli/
```

### Linting

```bash
flake8 cli/
```

### Type Checking

```bash
mypy cli/
```

## GitHub Actions

The CLI has its own workflow that runs:

- Code formatting checks (Black)
- Import sorting checks (isort)
- Import sorting checks (isort)
- Linting (Flake8)
- Type checking (MyPy)
- Tests (pytest)
Expand Down
15 changes: 14 additions & 1 deletion cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import typer
from typer import rich_utils

from commands import hello
try: # pragma: no cover - exercised implicitly via packaging
from .commands import hello
except ImportError: # pragma: no cover - fallback when run as a script from repo root
from commands import hello

rich_utils.USE_RICH = False
# Create the root CLI app
app = typer.Typer(help="101 Linux Commands CLI 🚀")


@app.command()
def build() -> None:
"""Build the ebook using Ibis."""

typer.echo("Building ebook with Ibis...")


# Register subcommands
app.add_typer(hello.app, name="hello")

Expand Down
48 changes: 25 additions & 23 deletions cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,61 @@
import os
import subprocess
import sys
from pathlib import Path
CLI_DIR = Path(__file__).parent
CLI_ENV = {**os.environ, "PYTHONIOENCODING": "utf-8"}


def test_cli_help():
"""Test that the CLI shows help."""
result = subprocess.run(
[sys.executable, "cli.py", "--help"],
def run_cli(*args: str) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[sys.executable, "cli.py", *args],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
encoding="utf-8",
cwd=CLI_DIR,
env=CLI_ENV,
)


def test_cli_help():
"""Test that the CLI shows help."""
result = run_cli("--help")
assert result.returncode == 0
assert "101 Linux Commands CLI" in result.stdout


def test_hello_command():
"""Test the hello command."""
result = subprocess.run(
[sys.executable, "cli.py", "hello", "greet"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
)
result = run_cli("hello", "greet")
assert result.returncode == 0
assert "Hello, World!" in result.stdout


def test_hello_command_with_name():
"""Test the hello command with a custom name."""
result = subprocess.run(
[sys.executable, "cli.py", "hello", "greet", "--name", "Linux"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
)
result = run_cli("hello", "greet", "--name", "Linux")
assert result.returncode == 0
assert "Hello, Linux!" in result.stdout


def test_hello_help():
"""Test the hello command help."""
result = subprocess.run(
[sys.executable, "cli.py", "hello", "--help"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
)
result = run_cli("hello", "--help")
assert result.returncode == 0
assert "Hello command group" in result.stdout


def test_build_command_stub():
"""Build command should print placeholder message."""
result = run_cli("build")
assert result.returncode == 0
assert "Building ebook with Ibis..." in result.stdout


if __name__ == "__main__":
test_cli_help()
test_hello_command()
test_hello_command_with_name()
test_hello_help()
test_build_command_stub()
print("✅ All tests passed!")
Loading