optparse_cmd.py 692 B

12345678910111213141516171819202122
  1. from optparse import make_option
  2. from django.core.management.base import BaseCommand
  3. class Command(BaseCommand):
  4. help = "Test optparse compatibility."
  5. args = ''
  6. option_list = BaseCommand.option_list + (
  7. make_option("-s", "--style", default="Rock'n'Roll"),
  8. make_option("-x", "--example")
  9. )
  10. def handle(self, *args, **options):
  11. options["example"]
  12. # BaseCommand default option is available
  13. options['verbosity']
  14. assert (
  15. isinstance(options['verbosity'], int), "verbosity option is not int, but %s" % type(options['verbosity'])
  16. )
  17. self.stdout.write("All right, let's dance %s." % options["style"])