Opened 5 years ago

Last modified 2 years ago

#14909 new New feature

Adding custom command requires code duplication from Command.handle() if one want to use options like verbosity.

Reported by: zimnyx 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

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 (7)

comment:1 Changed 5 years ago by russellm

  • Component changed from Uncategorized to Core framework
  • milestone set to 2.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by ramiro

See also #10080 and #13760.

comment:3 Changed 4 years ago by jaddison

  • Severity set to Normal
  • Type set to New feature

comment:4 Changed 4 years ago by jacob

Milestone 2.0 deleted

comment:3 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 2 years ago by aaugustin

  • Component changed from Core (Other) to Core (Management commands)
Note: See TracTickets for help on using tickets.
Back to Top