It is straight forward creating a string parameter such as --test_email_address
below.
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--test_email_address',
action='store',
type="string",
dest='test_email_address',
help="Specifies test email address."),
make_option('--vpds',
action='store',
type='list', /// ??? Throws exception
dest='vpds',
help="vpds list [,]"),
)
But how can I define a list to be passed in? such as [1, 3, 5]
sys. argv is used in python to retrieve command line arguments at runtime. For a program to be able to use it, it has to be imported from the “sys” module. The arguments so obtained are in the form of an array named sys.
django-admin is Django's command-line utility for administrative tasks. This document outlines all it can do. In addition, manage.py is automatically created in each Django project.
You should add a default value and change the action to 'append'
:
make_option('--vpds',
action='append',
default=[],
dest='vpds',
help="vpds list [,]"),
The usage is as follows:
python manage.py my_command --vpds arg1 --vpds arg2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With