1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #22985 -- Made call_command accept option name parameter

Thanks giulettamasina for the report and Tim Graham for the review.
This commit is contained in:
Claude Paroz
2014-08-09 21:03:19 +02:00
parent 8f9862cd4d
commit 2cc8ffe258
5 changed files with 48 additions and 6 deletions

View File

@@ -102,8 +102,12 @@ def call_command(name, *args, **options):
# Simulate argument parsing to get the option defaults (see #10080 for details).
parser = command.create_parser('', name)
if command.use_argparse:
# Use the `dest` option name from the parser option
opt_mapping = dict((sorted(s_opt.option_strings)[0].lstrip('-').replace('-', '_'), s_opt.dest)
for s_opt in parser._actions if s_opt.option_strings)
arg_options = dict((opt_mapping.get(key, key), value) for key, value in options.items())
defaults = parser.parse_args(args=args)
defaults = dict(defaults._get_kwargs(), **options)
defaults = dict(defaults._get_kwargs(), **arg_options)
else:
# Legacy optparse method
defaults, _ = parser.parse_args(args=[])