#29152: Allow more control over ArgumentParser initialization in management
commands
-------------------------------------+-------------------------------------
     Reporter:  Dmitry               |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Core (Management     |                  Version:  2.0
  commands)                          |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Dmitry):

 Replying to [comment:3 Tim Graham]:
 > Would a hook to provide some additional keyword arguments be sufficient?
 Yeah, this will be great, maybe the better way. I was thinking about way
 to implement this, but was unable to find beautiful enough way to add such
 hook. Maybe you have some good ideas.

 As a reference my idea was something like this:
 1. Add parser_kwargs argument in BaseCommand.__init__, defaults to {}
 {{{
         def __init__(self, stdout=None, stderr=None, no_color=False,
 parser_kwargs=None):
         self.stdout = OutputWrapper(stdout or sys.stdout)
         self.stderr = OutputWrapper(stderr or sys.stderr)
         if no_color:
             self.style = no_style()
         else:
             self.style = color_style()
             self.stderr.style_func = self.style.ERROR
        if not parser_kwargs:
            parser_kwargs = {}
 }}}

 2. use parser_kwargs in create_parser method
 {{{
     def create_parser(self, prog_name, subcommand):
         """
         Create and return the ``ArgumentParser`` which will be used to
         parse the arguments to this command.
         """
         if not 'prog' in self.parser_kwargs:
             self.parser_kwargs['prog'] = os.path.basename(prog_name),
 subcommand)
         if not 'description' in self.parser_kwargs:
             self.parser_kwargs['description'] = self.help or None
         parser = CommandParser(
             self, **self.parser_kwargs
         )
 }}}

 The problem is that in this case you will have two conflicting way to
 define description (using parser_kwargs or help).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29152#comment:4>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.6877615d89a56a1112cbdd236c41eb4f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to