REQUEST: Give LabelCommand an option for default behavior (when no labels are specified)
|Reported by:||maaku||Owned by:||nobody|
|Component:||Core (Management commands)||Version:||master|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||no|
The LabelCommand class is handy, but I've found circumstances where I need a default behavior when no labels are specified on the command line. For example, when specifying directories os.getcwd() provides a reasonable default and a convenient shorthand. Unless I missed something, implementing these commands required reimplementing LabelCommand.handle with the default hard coded in. Obviously violates DRY.
- Add field "default_label" to LabelCommand with value "None"
- Switch (line 317-318 in django/trunk/django/core/management/base.py)
if not labels: raise CommandError('Enter at least one %s.' % self.label)
if not labels: if not self.default_label raise CommandError('Enter at least one %s.' % self.label) else: labels = [self.default_label]
or something similar.
Patch is attached.
Change History (8)
Changed 5 years ago by maaku
comment:1 Changed 5 years ago by Alex
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted