add_arguments() configures a Django management command's command-line interface. Django's BaseCommand supplies the argument parser; this method receives it and registers positional arguments or flags through parser.add_argument(). section 9.3 section 9.6
Use the method to define how users supply command-line input:
- Register flags with leading dashes, such as --last_name, and optionally provide a short form such as -l. section 9.3
- Pass help text to describe each argument in the command's automatically available help screen. section 9.3 section 9.6
- Let handle() receive the parsed positional arguments and flags through its options parameter. section 9.6
Filtering the musicians command
A musicians command can define parser.add_argument("--last_name", "-l", help="Query musicians by last name") alongside --first_name and --birth. Users can then run python manage.py musicians --last_name Loblaw or combine --first_name O with --last_name B. Invalid input such as --birth tomorrow can produce a concise CommandError.
