#29152: management commands rigid ArgumentParser initialization
               Reporter:  Dmitry     |          Owner:  nobody
                   Type:  New        |         Status:  new
  feature                            |
              Component:  Core       |        Version:  2.0
  (Management commands)              |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
 Hello everyone.
 Noticed today that there is no way to customize CommandParser
 (ArgumentParser subclass), initialized in management commands
 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
 to add default values to help page, but was unable to do this properly.
 There is also some other usefull keyword arguments available in

 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),
             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.

Ticket URL: <https://code.djangoproject.com/ticket/29152>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to