Skip to content

Commit

Permalink
fix help prog names
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Dec 26, 2023
1 parent 8a93539 commit 482f145
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
10 changes: 7 additions & 3 deletions django_typer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(
_resolved_params: t.Optional[t.Dict[str, t.Any]] = None,
**kwargs,
):
super().__init__(command, **kwargs)
super().__init__(command, parent=parent, **kwargs)
self.django_command = django_command
if not django_command and parent:
self.django_command = parent.django_command
Expand Down Expand Up @@ -324,6 +324,7 @@ def handle(self, *args, **options):
standalone_mode=False,
_resolved_params=options,
django_command=self,
prog_name=f"{sys.argv[0]} {self.typer_app.info.name}",
)

return super().__new__(
Expand Down Expand Up @@ -485,17 +486,20 @@ class CommandNode:
name: str
command: t.Union[TyperCommandWrapper, TyperGroupWrapper]
context: TyperContext
parent: t.Optional["CommandNode"] = None
children: t.Dict[str, "CommandNode"]

def __init__(
self,
name: str,
command: t.Union[TyperCommandWrapper, TyperGroupWrapper],
context: TyperContext,
parent: t.Optional["CommandNode"] = None,
):
self.name = name
self.command = command
self.context = context
self.parent = parent
self.children = {}

def print_help(self):
Expand Down Expand Up @@ -564,11 +568,11 @@ def _build_cmd_tree(
node: t.Optional[CommandNode] = None,
):
ctx = Context(cmd, info_name=info_name, parent=parent, django_command=self)
current = self.CommandNode(cmd.name, cmd, ctx)
current = self.CommandNode(cmd.name, cmd, ctx, parent=node)
if node:
node.children[cmd.name] = current
for cmd in self._filter_commands(ctx):
self._build_cmd_tree(cmd, ctx, info_name=cmd.name, node=current)
self._build_cmd_tree(cmd, parent=ctx, info_name=cmd.name, node=current)
return current

def __init_subclass__(cls, **_):
Expand Down
2 changes: 1 addition & 1 deletion django_typer/tests/click_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@click.group(
context_settings={"allow_interspersed_args": True, "ignore_unknown_options": True}
# context_settings={"allow_interspersed_args": True, "ignore_unknown_options": True}
)
@click.argument("name")
@click.option("--verbose", "-v", is_flag=True, help="Enables verbose mode.")
Expand Down
5 changes: 5 additions & 0 deletions django_typer/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,18 @@ def test_helps(self, top_level_only=False):
help_output_top = run_command(self.cmd_name, "--help")
cmd.print_help("./manage.py", self.cmd_name)
self.assertEqual(help_output_top.strip(), buffer.getvalue().strip())
self.assertIn(f"Usage: ./manage.py {self.cmd_name} [OPTIONS]", help_output_top)

if not top_level_only:
buffer.truncate(0)
buffer.seek(0)
callback_help = run_command(self.cmd_name, "5", self.cmd_name, "--help")
cmd.print_help("./manage.py", self.cmd_name, self.cmd_name)
self.assertEqual(callback_help.strip(), buffer.getvalue().strip())
self.assertIn(
f"Usage: ./manage.py {self.cmd_name} P1 {self.cmd_name} [OPTIONS] ARG1 ARG2",
callback_help,
)

def test_command_line(self):
self.assertEqual(
Expand Down
2 changes: 1 addition & 1 deletion django_typer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from typing import Annotated, Optional

from typer import Option, echo
from typer import Option

_COMMON_PANEL = "Django"

Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-typer"
version = "0.1.0b"
version = "0.2.0"
description = "Use Typer to define the CLI for your Django management commands."
authors = ["Brian Kohan <[email protected]>"]
license = "MIT"
Expand All @@ -13,11 +13,12 @@ classifiers = [
"Framework :: Django",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
Expand All @@ -39,7 +40,7 @@ exclude = ["django_typer/tests"]

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Django = ">=3.2,<5.0"
Django = ">=3.2,<6.0"
typer = "^0.9.0"

[tool.poetry.group.dev.dependencies]
Expand Down Expand Up @@ -110,7 +111,7 @@ addopts = [
"--cov-report=term-missing:skip-covered",
"--cov-report=html",
"--cov-report=xml",
"--cov-fail-under=70"
"--cov-fail-under=90"
]

[tool.coverage.run]
Expand Down

0 comments on commit 482f145

Please sign in to comment.