1
0
mirror of https://github.com/django/django.git synced 2024-12-24 18:16:19 +00:00
django/tests/user_commands/management/commands/mutually_exclusive_required.py
Hasan Ramezani f06beea929 Fixed #32153 -- Fixed management commands when using required list options.
Thanks Mark Gajdosik for the report and initial patch.
2020-10-30 12:01:33 +01:00

21 lines
911 B
Python

from django.core.management.base import BaseCommand
class Command(BaseCommand):
def add_arguments(self, parser):
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--foo-id', type=int, nargs='?', default=None)
group.add_argument('--foo-name', type=str, nargs='?', default=None)
group.add_argument('--foo-list', type=int, nargs='+')
group.add_argument('--append_const', action='append_const', const=42)
group.add_argument('--const', action='store_const', const=31)
group.add_argument('--count', action='count')
group.add_argument('--flag_false', action='store_false')
group.add_argument('--flag_true', action='store_true')
def handle(self, *args, **options):
for option, value in options.items():
if value is not None:
self.stdout.write('%s=%s' % (option, value))