Opened 13 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 Russell Keith-Magee, 13 years ago

Component: UncategorizedCore framework
milestone: 2.0
Triage Stage: UnreviewedAccepted

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.

comment:2 by Ramiro Morales, 13 years ago

See also #10080 and #13760.

comment:3 by James Addison, 13 years ago

Severity: Normal
Type: New feature

comment:4 by Jacob, 13 years ago

Milestone 2.0 deleted

comment:3 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Aymeric Augustin, 11 years ago

Component: Core (Other)Core (Management commands)

comment:6 by Tim Graham, 9 years ago

Resolution: fixed
Status: newclosed

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.
Back to Top