﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29152	Allow more control over ArgumentParser initialization in management commands	Dmitry	humbertotm	"Hello everyone.
Noticed today that there is no way to customize CommandParser (ArgumentParser subclass), initialized in management commands (https://github.com/django/django/blob/master/django/core/management/base.py#L227). There is no option (or i was unable to find it - please correct me in this case) to pass any kwargs in CommandParser constructor. The public method create_parser contains some django-related hard-coded add_arguments calls, so overriding it directly leads to some copy paste. 

I needed to use some custom formatter for ArgumentParser (https://docs.python.org/3/library/argparse.html?highlight=argparse#argparse.ArgumentDefaultsHelpFormatter) to add default values to help page, but was unable to do this properly. There is also some other usefull keyword arguments available in ArgumentParser. 

As a proposal a new method could be added to BaseCommand (let's say BaseCommand.get_parser_instance), for example like this:

{{{
def get_parser_instance(self):
        return CommandParser(
            self, prog=""%s %s"" % (os.path.basename(prog_name), subcommand),
            description=self.help or None,
        )

def create_parser(self, prog_name, subcommand)::
       parser = self.get_parser_instance()
       ... etc
}}}

This should not break anything in BaseCommand, but will allow have more control on parser's creation overriding just get_parser_instance method.
Please sorry for mistakes."	Cleanup/optimization	closed	Core (Management commands)	2.0	Normal	fixed		Tom Forbes	Accepted	1	0	1	0	0	0
