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
13 changes: 13 additions & 0 deletions src/serious_scaffold/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ def run() -> None:
"""Run command."""


# NOTE(huxuan): callback is required for single command as a subcommand in typer.
# And it is a convenient way to document the cli here.
# Reference: https://typer.tiangolo.com/tutorial/commands/one-or-multiple/#one-command-and-one-callback
# BTW, `no_args_is_help` is set to `True` to avoid error when invoking the cli with no
# subcommands. The default behavior is strange and might change in the future.
# Reference: https://github.com/tiangolo/typer/issues/328
@app.callback(no_args_is_help=True)
def main() -> None:
"""CLI for Serious Scaffold Python."""


# NOTE(huxuan): click object is used for document generation.
# Reference: https://github.com/tiangolo/typer/issues/200#issuecomment-796485787
typer_click_object = typer.main.get_command(app)


Expand Down
16 changes: 0 additions & 16 deletions src/{{ module_name }}/cli.py

This file was deleted.

29 changes: 29 additions & 0 deletions src/{{ module_name }}/cli.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Command Line Interface."""
import typer

app = typer.Typer()


@app.command()
def run() -> None:
"""Run command."""


# NOTE(huxuan): callback is required for single command as a subcommand in typer.
# And it is a convenient way to document the cli here.
# Reference: https://typer.tiangolo.com/tutorial/commands/one-or-multiple/#one-command-and-one-callback
# BTW, `no_args_is_help` is set to `True` to avoid error when invoking the cli with no
# subcommands. The default behavior is strange and might change in the future.
# Reference: https://github.com/tiangolo/typer/issues/328
@app.callback(no_args_is_help=True)
def main() -> None:
"""CLI for {{ project_name }}."""


# NOTE(huxuan): click object is used for document generation.
# Reference: https://github.com/tiangolo/typer/issues/200#issuecomment-796485787
typer_click_object = typer.main.get_command(app)


if __name__ == "__main__":
app() # pragma: no cover
9 changes: 8 additions & 1 deletion tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
runner = CliRunner()


def test_app() -> None:
def test_cli() -> None:
"""Tests for cli."""
result = runner.invoke(app)
assert result.exit_code == 0
assert "Usage" in result.output


def test_cli_run() -> None:
"""Tests for run subcommand of the cli."""
result = runner.invoke(app, "run")
assert result.exit_code == 0
assert not result.output
9 changes: 8 additions & 1 deletion tests/cli_test.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ from {{ module_name }}.cli import app
runner = CliRunner()


def test_app() -> None:
def test_cli() -> None:
"""Tests for cli."""
result = runner.invoke(app)
assert result.exit_code == 0
assert "Usage" in result.output


def test_cli_run() -> None:
"""Tests for run subcommand of the cli."""
result = runner.invoke(app, "run")
assert result.exit_code == 0
assert not result.output