Ticket #10080: 10080.diff

File 10080.diff, 2.4 KB (added by Alexander Koshelev, 16 years ago)

Patch

  • django/core/management/__init__.py

     
    11import os
    22import sys
    3 from optparse import OptionParser
     3from optparse import OptionParser, NO_DEFAULT
    44import imp
    55
    66import django
     
    155155            klass = load_command_class(app_name, name)
    156156    except KeyError:
    157157        raise CommandError, "Unknown command: %r" % name
    158     return klass.execute(*args, **options)
    159158
     159    defaults = dict([(o.dest, o.default)
     160                      for o in klass.option_list if o.default is not NO_DEFAULT])
     161    defaults.update(options)
     162
     163    return klass.execute(*args, **defaults)
     164
    160165class LaxOptionParser(OptionParser):
    161166    """
    162167    An option parser that doesn't raise any errors on unknown options.
  • tests/modeltests/user_commands/models.py

     
    1717>>> from django.core import management
    1818
    1919# Invoke a simple user-defined command
    20 >>> management.call_command('dance')
    21 I don't feel like dancing.
     20>>> management.call_command('dance', style="Jive")
     21I don't feel like dancing Jive.
    2222
    2323# Invoke a command that doesn't exist
    2424>>> management.call_command('explode')
     
    2626...
    2727CommandError: Unknown command: 'explode'
    2828
     29# Invoke a command with default option `style`
     30>>> management.call_command('dance')
     31I don't feel like dancing Rock'n'Roll.
    2932
    3033"""}
  • tests/modeltests/user_commands/management/commands/dance.py

     
     1from optparse import make_option
    12from django.core.management.base import BaseCommand
    23
    34class Command(BaseCommand):
     
    56    args = ''
    67    requires_model_validation = True
    78
     9    option_list =[
     10        make_option("-s", "--style", default="Rock'n'Roll")
     11    ]
     12
    813    def handle(self, *args, **options):
    9         print "I don't feel like dancing."
    10  No newline at end of file
     14        print "I don't feel like dancing %s." % options["style"]
Back to Top