Skip to content

Instantly share code, notes, and snippets.

@ryanbraganza
Created January 3, 2013 00:00
Show Gist options
  • Select an option

  • Save ryanbraganza/4439548 to your computer and use it in GitHub Desktop.

Select an option

Save ryanbraganza/4439548 to your computer and use it in GitHub Desktop.
django management command to greet cindy
from django.core.management.base import BaseCommand, CommandError
from optparse import make_option
class Command(BaseCommand):
args = "<how many times to say hi to cindy>"
help = "Says hi to Cindy"
option_list = BaseCommand.option_list + (
make_option('--with-smily-face',
action='store_true',
dest='with_smily_face',
default=False,
help='Add a smily face on each greeting',
),
)
def handle(self, num_times, **options):
with_smily_face = options['with_smily_face']
for _ in range(int(num_times)):
if with_smily_face:
print "hi Cindy :)"
else:
print "hi Cindy"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment