| 1 |
from django.core.management.base import BaseCommand, CommandError |
| 2 |
|
| 3 |
|
| 4 |
class Command(BaseCommand): |
| 5 |
help = "Dance around like a madman." |
| 6 |
args = "" |
| 7 |
requires_system_checks = "__all__" |
| 8 |
|
| 9 |
def add_arguments(self, parser): |
| 10 |
parser.add_argument("integer", nargs="?", type=int, default=0) |
| 11 |
parser.add_argument("-s", "--style", default="Rock'n'Roll") |
| 12 |
parser.add_argument("-x", "--example") |
| 13 |
parser.add_argument("--opt-3", action="store_true", dest="option3") |
| 14 |
|
| 15 |
def handle(self, *args, **options): |
| 16 |
example = options["example"] |
| 17 |
if example == "raise": |
| 18 |
raise CommandError(returncode=3) |
| 19 |
if options["verbosity"] > 0: |
| 20 |
self.stdout.write("I don't feel like dancing %s." % options["style"]) |
| 21 |
self.stdout.write(",".join(options)) |
| 22 |
if options["integer"] > 0: |
| 23 |
self.stdout.write( |
| 24 |
"You passed %d as a positional argument." % options["integer"] |
| 25 |
) |