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
18 changes: 13 additions & 5 deletions src/wristpy/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class NonwearAlgorithms(str, Enum):
detach = "detach"


def version_check(version: bool) -> None:
"""Print the current version of wristpy and exit."""
if version:
typer.echo(f"Wristpy version: {config.get_version()}")
raise typer.Exit()


@app.command()
def main(
input: pathlib.Path = typer.Argument(
Expand Down Expand Up @@ -123,16 +130,17 @@ def main(
"Defaults to INFO if not included.",
),
version: bool = typer.Option(
False, "-V", "--version", help="Show the version and exit."
False,
"-V",
"--version",
help="Print the current version of wristpy and exit.",
is_eager=True,
callback=version_check,
),
) -> None:
"""Run wristpy orchestrator with command line arguments."""
from wristpy.core import orchestrator

if version:
typer.echo(f"Wristpy version: {config.get_version()}")
raise typer.Exit()

log_level = logging.INFO
if verbosity:
log_level = logging.DEBUG
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,30 @@ def test_main_verbosity(
verbosity=logging.DEBUG,
output_filetype=None,
)


def test_main_version(
create_typer_cli_runner: testing.CliRunner,
) -> None:
"""Test cli version output."""
result = create_typer_cli_runner.invoke(cli.app, ["--version"])

assert result.exit_code == 0
assert "Wristpy version" in result.output


def test_main_version_with_options(
create_typer_cli_runner: testing.CliRunner,
sample_data_gt3x: pathlib.Path,
mocker: pytest_mock.MockerFixture,
) -> None:
"""Test other arguments and options are ignored when --version is passed."""
mock_run = mocker.patch.object(orchestrator, "run")

result = create_typer_cli_runner.invoke(
cli.app, [str(sample_data_gt3x), "-e", "5", "--version"]
)

assert result.exit_code == 0
assert "Wristpy version" in result.output
mock_run.assert_not_called()