Opened 6 years ago

Closed 13 months 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: 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


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

See also #10080 and #13760.

comment:3 Changed 5 years ago by jaddison

  • Severity set to Normal
  • Type set to New feature

comment:4 Changed 5 years ago by jacob

Milestone 2.0 deleted

comment:3 Changed 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 5 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 3 years ago by aaugustin

  • Component changed from Core (Other) to Core (Management commands)

comment:6 Changed 13 months ago by timgraham

  • Resolution set to fixed
  • Status changed from new to 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.
Back to Top