Opened 4 years ago

Last modified 4 years ago

#32153 closed Bug

Support for list arguments inside exclusive required groups — at Version 1

Reported by: Mark Gajdosik Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords: call_command, exclusive group, nargs, error
Cc: Hasan Ramezani Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mark Gajdosik)

Are there any plans to add support for the following?

from django.core.management import BaseCommand

class Command(BaseCommand):
    def add_arguments(self, parser):
        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument('--foo', nargs='+', type=int)

    def handle(self, *args, **options):
        pass

When calling the above using call_command:

call_command('call_command_test', foo=[1, 2, 3])
# Raises: django.core.management.base.CommandError: Error: one of the arguments --foo is required

call_command('call_command_test', '--foo=1', '--foo=2', '--foo=3')
# Option 'foo' will be of value [3]

I can't think of any workarounds other than setting type=str (somehow, that works fine) and coercing manually. Thank you!

Change History (1)

comment:1 by Mark Gajdosik, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top