From 51f076a026af2b1e646929501aa2ee9fa3529560 Mon Sep 17 00:00:00 2001 From: Jacob Tomlinson Date: Wed, 10 Jan 2024 16:34:58 +0000 Subject: [PATCH] Make the default action to show help (#283) --- examples/kubectl-ng/kubectl_ng/cli.py | 2 +- examples/kubectl-ng/kubectl_ng/tests/test_cli.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 examples/kubectl-ng/kubectl_ng/tests/test_cli.py diff --git a/examples/kubectl-ng/kubectl_ng/cli.py b/examples/kubectl-ng/kubectl_ng/cli.py index 6cb1ece6..3ea06ebb 100644 --- a/examples/kubectl-ng/kubectl_ng/cli.py +++ b/examples/kubectl-ng/kubectl_ng/cli.py @@ -32,7 +32,7 @@ def register(app, func, alias=None): app.command()(func) -app = typer.Typer() +app = typer.Typer(no_args_is_help=True) register(app, api_resources) register(app, api_versions) register(app, create) diff --git a/examples/kubectl-ng/kubectl_ng/tests/test_cli.py b/examples/kubectl-ng/kubectl_ng/tests/test_cli.py new file mode 100644 index 00000000..f4190390 --- /dev/null +++ b/examples/kubectl-ng/kubectl_ng/tests/test_cli.py @@ -0,0 +1,12 @@ +# SPDX-FileCopyrightText: Copyright (c) 2023-2024, Kr8s Developers (See LICENSE for list) +# SPDX-License-Identifier: BSD 3-Clause License +from kubectl_ng.cli import app +from typer.testing import CliRunner + +runner = CliRunner() + + +def test_help_default(): + result = runner.invoke(app, []) + assert result.exit_code == 0 + assert "Usage:" in result.stdout