Opened 14 years ago
Closed 9 years ago
#14909 closed New feature (fixed)
Adding custom command requires code duplication from Command.handle() if one want to use options like verbosity.
Reported by: | Piotr Czachur | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
# django/core/management/commands/test.py def handle(self, *test_labels, **options): # ... verbosity = int(options.get('verbosity', 1)) interactive = options.get('interactive', True) failfast = options.get('failfast', False) # ...
People who write custom commands make use of options like verbosity, etc.
This code should be moved to separate function setup_options(), so people who write custom command don't have to "copy&paste" that code into their' CustomCommand.handle() implementation.
Change History (8)
comment:1 by , 14 years ago
Component: | Uncategorized → Core framework |
---|---|
milestone: | → 2.0 |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:5 by , 12 years ago
Component: | Core (Other) → Core (Management commands) |
---|
comment:6 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I think the issue of code duplication has been minimized since the migration to argparse. See 4b4524291adbc78ab880317124803fc37a2e414a.
Note:
See TracTickets
for help on using tickets.
Agreed that this is inconsistent and inconvenient, but it's also very difficult to change without breaking backwards incompatibility. Any existing command that needs verbosity will already be handling it; if we add verbosity handling, the options will clash.
Putting this on the 2.0 milestone as something we can address when backwards compatibility isn't an issue.