Skip to content

Commit 9786a73

Browse files
committed
Improve Django commands integration and --help fix
1 parent 043b3bd commit 9786a73

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ellar_django/commands.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class _CommandItem(t.NamedTuple):
1919
def get_command_description(command_name: str) -> str:
2020
module = get_commands()[command_name]
2121
CommandClass = load_command_class(module, command_name)
22-
return CommandClass.help or ""
22+
CommandClass.help = f"[{module.split('.')[0]}] {CommandClass.help}"
23+
return CommandClass.help
2324

2425

2526
def generate_command_list() -> t.List[_CommandItem]:
@@ -36,15 +37,20 @@ def generate_command_list() -> t.List[_CommandItem]:
3637
_django_support_commands = generate_command_list()
3738

3839

39-
def version_callback(ctx: click.Context, _: t.Any, value: bool) -> None:
40+
def version_callback(ctx: click.Context, _: click.Parameter, value: bool) -> None:
4041
if value:
4142
click.echo(f"Django Version: {django.__version__}")
4243
ctx.exit()
4344

4445

46+
def show_help_callback(ctx: click.Context, _: click.Parameter, value: bool) -> None:
47+
command_args = ["manage.py", ctx.info_name, "--help"]
48+
django.core.management.execute_from_command_line(command_args)
49+
50+
4551
@click.group(
4652
name="django",
47-
help="- Ellar Django Commands",
53+
help="Ellar Django Commands",
4854
)
4955
@click.option(
5056
"-v",
@@ -70,6 +76,7 @@ def _add_django_command(command_item: _CommandItem) -> None:
7076
@click.option(
7177
"-h",
7278
"--help",
79+
callback=show_help_callback,
7380
help="Show the command help.",
7481
is_flag=True,
7582
expose_value=False,

0 commit comments

Comments
 (0)