Re: [Django] #33657: Customizable management command formatters. (was: Custom command help formatting destroyed)

8 views
Skip to first unread message

Django

unread,
Apr 25, 2022, 2:36:15 AM4/25/22
to django-...@googlegroups.com
#33657: Customizable management command formatters.
-------------------------------------+-------------------------------------
Reporter: James Pic | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Management | Version: 4.0
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* type: Bug => Cleanup/optimization
* easy: 0 => 1
* stage: Unreviewed => Accepted


Comment:

It seems reasonable, to make it customizable by passing via `kwargs` to
the [https://docs.djangoproject.com/en/4.0/howto/custom-management-
commands/#django.core.management.BaseCommand.create_parser
BaseCommand.create_parser() (as documented)]:
{{{#!diff
diff --git a/django/core/management/base.py
b/django/core/management/base.py
index f0e711ac76..52407807d8 100644
--- a/django/core/management/base.py
+++ b/django/core/management/base.py
@@ -286,10 +286,10 @@ class BaseCommand:
Create and return the ``ArgumentParser`` which will be used to
parse the arguments to this command.
"""
+ kwargs.setdefault("formatter_class", DjangoHelpFormatter)
parser = CommandParser(
prog="%s %s" % (os.path.basename(prog_name), subcommand),
description=self.help or None,
- formatter_class=DjangoHelpFormatter,
missing_args_message=getattr(self, "missing_args_message",
None),
called_from_command_line=getattr(self,
"_called_from_command_line", None),
**kwargs,
}}}

What do you think?

--
Ticket URL: <https://code.djangoproject.com/ticket/33657#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages