Q:

'required' is an invalid argument for positionals in python command

I want to implement import feature with required and optional parameters, to run this in this way:
python manage.py import --mode archive

where --mode is required and archive also.
I'm using argparse library.
class Command(BaseCommand):
    help = 'Import'

    def add_arguments(self, parser):
        parser.add_argument('--mode',
            required=True,
        )
        parser.add_argument('archive',
            required=True,
            default=False,
            help='Make import archive events'
        )

But I recived error:
TypeError: 'required' is an invalid argument for positionals

A:

You created a positional argument (no -- option in front of the name). Positional arguments are always required. You can't use required=True for such options, just drop the required. Drop the default too; a required argument can't have a default value (it would never be used anyway):
parser.add_argument('archive',
    help='Make import archive events'
)

If you meant for archive to be a command-line switch, use --archive instead.

