Cover the case in which BaseCommand.create_parser retursn optparse.OptionParser.

This commit is contained in:
Jannis Leidel 2015-02-13 21:52:47 +01:00
parent f35e7e57e0
commit 6ce3740365

View file

@ -34,11 +34,18 @@ def install(check_options=False):
def create_parser(self, prog_name, subcommand):
parser = orig_create_parser(self, prog_name, subcommand)
if not isinstance(parser, OptionParser):
if isinstance(parser, OptionParser):
# in case the option_list is set the create_parser
# will actually return a OptionParser for backward
# compatibility. It uses BaseCommand.use_argparse
# to decide that, which checks for the option_list list
base.BaseCommand.option_list += configuration_options
else:
# probably argparse, let's not import argparse though
parser.add_argument(CONFIGURATION_ARGUMENT,
help=CONFIGURATION_ARGUMENT_HELP)
return parser
base.BaseCommand.create_parser = create_parser
else:
# add the configuration option to all management commands