Opened 8 years ago

Closed 8 years ago

#25736 closed New feature (wontfix)

Define management commands via function

Reported by: Olivier Le Thanh Duong Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Olivier Le Thanh Duong)

Creating a new management command currently require a lot of boilerplate to remember, a small part of it is having to subclass a command. This is often overkill when you just have a function and don't need complex arguments parsing.

So I'm proposing to allow using function for Command.

I'm attaching an idea of an implementation but I'm not really set on it. This would allow to write:

    from django.core.management.base import LabelCommand

    def print_label(label):
        "Help message"
        print label

    Command = LabelCommand.from_func(print_label, can_import_settings=False)

Proposed implementation: https://github.com/django/django/compare/master...olethanh:ticket_27536?expand=1

Attachments (1)

e.patch (2.0 KB ) - added by Olivier Le Thanh Duong 8 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by Olivier Le Thanh Duong, 8 years ago

Description: modified (diff)
Has patch: set

comment:2 by Olivier Le Thanh Duong, 8 years ago

Needs documentation: set
Needs tests: set
Patch needs improvement: set

by Olivier Le Thanh Duong, 8 years ago

Attachment: e.patch added

comment:3 by Tim Graham, 8 years ago

Could you raise the idea on the DevelopersMailingList to get more feedback on the idea?

comment:4 by Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed

Please reopen if you can start a discussion and get a consensus to add this. Thanks!

Note: See TracTickets for help on using tickets.
Back to Top