Ticket #10080: 10080.diff
File 10080.diff, 2.4 KB (added by , 16 years ago) |
---|
-
django/core/management/__init__.py
1 1 import os 2 2 import sys 3 from optparse import OptionParser 3 from optparse import OptionParser, NO_DEFAULT 4 4 import imp 5 5 6 6 import django … … 155 155 klass = load_command_class(app_name, name) 156 156 except KeyError: 157 157 raise CommandError, "Unknown command: %r" % name 158 return klass.execute(*args, **options)159 158 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 160 165 class LaxOptionParser(OptionParser): 161 166 """ 162 167 An option parser that doesn't raise any errors on unknown options. -
tests/modeltests/user_commands/models.py
17 17 >>> from django.core import management 18 18 19 19 # 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") 21 I don't feel like dancing Jive. 22 22 23 23 # Invoke a command that doesn't exist 24 24 >>> management.call_command('explode') … … 26 26 ... 27 27 CommandError: Unknown command: 'explode' 28 28 29 # Invoke a command with default option `style` 30 >>> management.call_command('dance') 31 I don't feel like dancing Rock'n'Roll. 29 32 30 33 """} -
tests/modeltests/user_commands/management/commands/dance.py
1 from optparse import make_option 1 2 from django.core.management.base import BaseCommand 2 3 3 4 class Command(BaseCommand): … … 5 6 args = '' 6 7 requires_model_validation = True 7 8 9 option_list =[ 10 make_option("-s", "--style", default="Rock'n'Roll") 11 ] 12 8 13 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"]