Skip to content

Commit

Permalink
fix bug where no init commands with multiple subcommands was not hono…
Browse files Browse the repository at this point in the history
…ring the django_params list
  • Loading branch information
bckohan committed Jan 24, 2024
1 parent b010430 commit 7a153f0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
11 changes: 8 additions & 3 deletions django_typer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,12 @@ def common_params(self):

class TyperGroupWrapper(DjangoAdapterMixin, CoreTyperGroup):
def common_params(self):
if hasattr(self, "django_command") and self.django_command._has_callback:
if (
(
hasattr(self, "django_command") and
self.django_command._has_callback
) or getattr(self, "common_init", False)
):
return [
param
for param in _get_common_params()
Expand Down Expand Up @@ -742,9 +747,9 @@ def get_ctor(attr):
cls=type(
"_AdaptedCallback",
(TyperGroupWrapper,),
{"django_command": cls, "callback_is_method": False},
{"django_command": cls, "callback_is_method": False, "common_init": True},
)
)(_common_options)
)(lambda: None)

super().__init__(name, bases, attrs, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion django_typer/management/commands/shellcompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from typer import Argument, Option, echo
from typer.completion import Shells, completion_init

from django_typer import COMPLETE_VAR, TyperCommand, command, get_command
from django_typer import COMPLETE_VAR, TyperCommand, command, get_command, initialize

try:
from shellingham import detect_shell
Expand Down
38 changes: 12 additions & 26 deletions django_typer/tests/test_app/helps/groups.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Usage: ./manage.py groups [OPTIONS] COMMAND [ARGS]...

Test multiple groups commands and callbacks
Expand All @@ -7,31 +6,18 @@
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Django ─────────────────────────────────────────────────────────────────────╮
│ --version Show program's version number │
│ and exit. │
│ --verbosity INTEGER RANGE [0<=x<=3] Verbosity level; 0=minimal │
│ output, 1=normal output, │
│ 2=verbose output, 3=very │
│ verbose output │
│ [default: 1] │
│ --settings TEXT The Python path to a settings │
│ module, e.g. │
│ "myproject.settings.main". If │
│ this isn't provided, the │
│ DJANGO_SETTINGS_MODULE │
│ environment variable will be │
│ used. │
│ --pythonpath PATH A directory to add to the │
│ Python path, e.g. │
│ "/home/djangoprojects/myproje… │
│ [default: None] │
│ --traceback Raise on CommandError │
│ exceptions │
│ --no-color Don't colorize the command │
│ output. │
│ --force-color Force colorization of the │
│ command output. │
│ --skip-checks Skip system checks. │
│ --version Show program's version number and exit. │
│ --settings TEXT The Python path to a settings module, e.g. │
│ "myproject.settings.main". If this isn't │
│ provided, the DJANGO_SETTINGS_MODULE environment │
│ variable will be used. │
│ --pythonpath PATH A directory to add to the Python path, e.g. │
│ "/home/djangoprojects/myproject". │
│ [default: None] │
│ --traceback Raise on CommandError exceptions │
│ --no-color Don't colorize the command output. │
│ --force-color Force colorization of the command output. │
│ --skip-checks Skip system checks. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ echo Echo the given message. │
Expand Down
2 changes: 0 additions & 2 deletions django_typer/tests/test_app2/helps/groups.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
│ 2=verbose output, 3=very │
│ verbose output │
│ [default: 1] │
│ --version Show program's version number │
│ and exit. │
│ --settings TEXT The Python path to a settings │
│ module, e.g. │
│ "myproject.settings.main". If │
Expand Down
6 changes: 6 additions & 0 deletions django_typer/tests/test_app2/management/commands/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class Command(GroupsCommand, epilog="Overridden from test_app."):
precision = 2
verbosity = 1

django_params = [
param
for param in GroupsCommand.django_params
if param != 'version'
]

@initialize()
def init(self, verbosity: types.Verbosity = verbosity):
"""
Expand Down

0 comments on commit 7a153f0

Please sign in to comment.