summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhinav Yadav <72503824+SirAbhi13@users.noreply.github.com>2022-06-20 21:04:52 +0530
committerGitHub <noreply@github.com>2022-06-20 17:34:52 +0200
commit2887b9f67cadc5295ef6a0574de2c2c8fdd66905 (patch)
treeb7c0c92f2769960ac2632a476b7bc1ec873c2ca3
parentd7f5bfd241666c0a76e90208da1e9ef81aec44db (diff)
Fixed #33657 -- Allowed customizing formatter class of argument parsers.
-rw-r--r--django/core/management/base.py2
-rw-r--r--tests/user_commands/tests.py9
2 files changed, 9 insertions, 2 deletions
diff --git a/django/core/management/base.py b/django/core/management/base.py
index d37d43d5c5..abc6f79a15 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,
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py
index 222a1c5835..b840ef8087 100644
--- a/tests/user_commands/tests.py
+++ b/tests/user_commands/tests.py
@@ -1,4 +1,5 @@
import os
+from argparse import ArgumentDefaultsHelpFormatter
from io import StringIO
from unittest import mock
@@ -408,8 +409,14 @@ class CommandTests(SimpleTestCase):
def test_create_parser_kwargs(self):
"""BaseCommand.create_parser() passes kwargs to CommandParser."""
epilog = "some epilog text"
- parser = BaseCommand().create_parser("prog_name", "subcommand", epilog=epilog)
+ parser = BaseCommand().create_parser(
+ "prog_name",
+ "subcommand",
+ epilog=epilog,
+ formatter_class=ArgumentDefaultsHelpFormatter,
+ )
self.assertEqual(parser.epilog, epilog)
+ self.assertEqual(parser.formatter_class, ArgumentDefaultsHelpFormatter)
def test_outputwrapper_flush(self):
out = StringIO()