Opened 7 years ago

Closed 3 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: master
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


# django/core/management/commands/
    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 Changed 7 years ago by Russell Keith-Magee

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 Changed 7 years ago by Ramiro Morales

See also #10080 and #13760.

comment:3 Changed 7 years ago by James Addison

Severity: Normal
Type: New feature

comment:4 Changed 7 years ago by Jacob

Milestone 2.0 deleted

comment:3 Changed 6 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 6 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 5 years ago by Aymeric Augustin

Component: Core (Other)Core (Management commands)

comment:6 Changed 3 years ago by Tim Graham

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