Skip to content

Commit b61c5b1

Browse files
committed
fix #78
1 parent ffdc7a3 commit b61c5b1

File tree

6 files changed

+66
-1
lines changed

6 files changed

+66
-1
lines changed

django_typer/management/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,12 @@ def _resolve_help(dj_cmd: "TyperCommand"):
17051705
cmd.help = hlp
17061706
elif not dj_cmd.typer_app.info.help:
17071707
dj_cmd.typer_app.info.help = hlp
1708+
elif (
1709+
dj_cmd.typer_app.info.help
1710+
and not dj_cmd.is_compound_command
1711+
and not dj_cmd.typer_app.registered_commands[0].help
1712+
):
1713+
dj_cmd.typer_app.registered_commands[0].help = dj_cmd.typer_app.info.help
17081714

17091715

17101716
def _names(tc: t.Union[typer.models.CommandInfo, Typer]) -> t.List[str]:

doc/source/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ v2.1.0
77

88
* Implemented `Move tests into top level dir. <https://github.com/bckohan/django-typer/issues/87>`_
99
* Implemented `Move core code out of __init__.py into management/__init__.py <https://github.com/bckohan/django-typer/issues/81>`_
10-
10+
* Fixed `Typer(help="") doesnt work. <https://github.com/bckohan/django-typer/issues/78>`_
1111

1212
v2.0.2
1313
======
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.utils.translation import gettext_lazy as _
2+
3+
from django_typer.management import Typer
4+
5+
6+
app = Typer(help=_("2: App help"))
7+
8+
9+
@app.command(help=_("1: Command help"))
10+
def native_helps():
11+
"""
12+
3: Docstring help
13+
"""
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.utils.translation import gettext_lazy as _
2+
3+
from django_typer.management import Typer
4+
5+
6+
app = Typer(help=_("2: App help"))
7+
8+
9+
@app.command()
10+
def native_helps():
11+
"""
12+
3: Docstring help
13+
"""
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.utils.translation import gettext_lazy as _
2+
3+
from django_typer.management import Typer
4+
5+
6+
app = Typer()
7+
8+
9+
@app.command()
10+
def native_helps():
11+
"""
12+
3: Docstring help
13+
"""

tests/test_help_precedence.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,23 @@ def test_help_from_other_dir(self):
178178
self.assertIn(f"Usage: {manage_py}", stdout)
179179
finally:
180180
os.chdir(cwd)
181+
182+
183+
class TestNativeHelpPrecedence(TestCase):
184+
def test_help_precedence_native1(self):
185+
buffer = StringIO()
186+
cmd = get_command("help_precedence_native1", no_color=True, stdout=buffer)
187+
cmd.print_help("./manage.py", "help_precedence_native1")
188+
self.assertIn("1: Command help", buffer.getvalue())
189+
190+
def test_help_precedence_native2(self):
191+
buffer = StringIO()
192+
cmd = get_command("help_precedence_native2", no_color=True, stdout=buffer)
193+
cmd.print_help("./manage.py", "help_precedence_native2")
194+
self.assertIn("2: App help", buffer.getvalue())
195+
196+
def test_help_precedence_native3(self):
197+
buffer = StringIO()
198+
cmd = get_command("help_precedence_native3", no_color=True, stdout=buffer)
199+
cmd.print_help("./manage.py", "help_precedence_native3")
200+
self.assertIn("3: Docstring help", buffer.getvalue())

0 commit comments

Comments
 (0)