Skip to content

Commit 8d90d49

Browse files
Makes all subcommands to print help when no arg is provided.
Co-authored-by: Piotr Kaznowski <[email protected]>
1 parent 0a27590 commit 8d90d49

File tree

11 files changed

+71
-5
lines changed

11 files changed

+71
-5
lines changed

cli/django.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pythonanywhere.snakesay import snakesay
77
from pythonanywhere.utils import ensure_domain
88

9-
app = typer.Typer()
9+
app = typer.Typer(no_args_is_help=True)
1010

1111

1212
@app.command()

cli/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pythonanywhere.files import PAPath
1010
from pythonanywhere.scripts_commons import get_logger
1111

12-
app = typer.Typer()
12+
app = typer.Typer(no_args_is_help=True)
1313

1414

1515
def setup(path: str, quiet: bool) -> PAPath:

cli/schedule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pythonanywhere.snakesay import snakesay
1111
from pythonanywhere.task import Task, TaskList
1212

13-
app = typer.Typer()
13+
app = typer.Typer(no_args_is_help=True)
1414

1515

1616
@app.command()

cli/students.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pythonanywhere.scripts_commons import get_logger
66
from pythonanywhere.students import Students
77

8-
app = typer.Typer()
8+
app = typer.Typer(no_args_is_help=True)
99

1010

1111
def setup(quiet: bool) -> Students:

cli/webapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pythonanywhere.snakesay import snakesay
1111
from pythonanywhere.utils import ensure_domain
1212

13-
app = typer.Typer()
13+
app = typer.Typer(no_args_is_help=True)
1414

1515

1616
@app.command()

tests/test_cli_django.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ def running_python_version():
3333
return ".".join(python_version().split(".")[:2])
3434

3535

36+
def test_main_subcommand_without_args_prints_help():
37+
result = runner.invoke(
38+
app,
39+
[],
40+
)
41+
assert result.exit_code == 0
42+
assert "Show this message and exit." in result.stdout
43+
44+
3645
def test_autoconfigure_calls_all_stuff_in_right_order(mock_django_project):
3746
result = runner.invoke(
3847
app,

tests/test_cli_pa.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typer.testing import CliRunner
2+
3+
from cli.pa import app
4+
5+
runner = CliRunner()
6+
7+
8+
def test_main_command_without_args_prints_help():
9+
result = runner.invoke(
10+
app,
11+
[],
12+
)
13+
assert result.exit_code == 0
14+
assert "This is a new experimental PythonAnywhere cli client." in result.stdout
15+
assert "Makes Django Girls tutorial projects deployment easy" in result.stdout
16+
assert "Perform some operations on files" in result.stdout
17+
assert "Manage scheduled tasks" in result.stdout
18+
assert "Perform some operations on students" in result.stdout
19+
assert "Everything for web apps" in result.stdout
20+
21+

tests/test_cli_path.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ def mock_file_path(mock_path):
4141
return mock_path
4242

4343

44+
def test_main_subcommand_without_args_prints_help():
45+
result = runner.invoke(
46+
app,
47+
[],
48+
)
49+
assert result.exit_code == 0
50+
assert "Show this message and exit." in result.stdout
51+
52+
4453
class TestGet:
4554
def test_exits_early_when_no_contents_for_given_path(self, mock_path):
4655
mock_path.return_value.contents = None

tests/test_cli_schedule.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ def mock_confirm(mocker):
4040
return mocker.patch("cli.schedule.typer.confirm")
4141

4242

43+
def test_main_subcommand_without_args_prints_help():
44+
result = runner.invoke(
45+
app,
46+
[],
47+
)
48+
assert result.exit_code == 0
49+
assert "Show this message and exit." in result.stdout
50+
51+
4352
class TestSet:
4453
def test_calls_all_stuff_in_right_order(self, mocker):
4554
mock_logger = mocker.patch("cli.schedule.get_logger")

tests/test_cli_students.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ def mock_students_delete(mock_students):
2222
return mock_students.return_value.delete
2323

2424

25+
def test_main_subcommand_without_args_prints_help():
26+
result = runner.invoke(
27+
app,
28+
[],
29+
)
30+
assert result.exit_code == 0
31+
assert "Show this message and exit." in result.stdout
32+
33+
2534
@pytest.mark.students
2635
class TestGet:
2736
def test_exits_early_with_error_when_api_does_not_return_expected_list(

0 commit comments

Comments
 (0)