diff --git a/django/core/management/base.py b/django/core/management/base.py
index f77add2..4c729cc 100644
a
|
b
|
class BaseCommand(object):
|
201 | 201 | leave_locale_alone = False |
202 | 202 | requires_system_checks = True |
203 | 203 | |
| 204 | to_implement = 'handle' # Method to implement by subclass |
| 205 | |
204 | 206 | def __init__(self, stdout=None, stderr=None, no_color=False): |
205 | 207 | self.stdout = OutputWrapper(stdout or sys.stdout) |
206 | 208 | self.stderr = OutputWrapper(stderr or sys.stderr) |
… |
… |
class BaseCommand(object):
|
421 | 423 | else: |
422 | 424 | self.stdout.write(msg) |
423 | 425 | |
| 426 | @classmethod |
| 427 | def from_func(klass, func, **kwargs): |
| 428 | """Create a command from a function |
| 429 | Example usage: |
| 430 | from django.core.management.base import LabelCommand |
| 431 | |
| 432 | def a(label): |
| 433 | "Help message" |
| 434 | print label |
| 435 | |
| 436 | Command = LabelCommand.from_func(a, can_import_settings=False) |
| 437 | """ |
| 438 | func_name = klass.to_implement |
| 439 | d = { |
| 440 | func_name: lambda self, *args, **kwargs: func(*args, **kwargs), |
| 441 | 'help': func.__doc__, |
| 442 | } |
| 443 | d.update(**kwargs) |
| 444 | return type(str('Command'), (klass,), d) |
| 445 | |
424 | 446 | def handle(self, *args, **options): |
425 | 447 | """ |
426 | 448 | The actual logic of the command. Subclasses must implement |
… |
… |
class AppCommand(BaseCommand):
|
439 | 461 | """ |
440 | 462 | missing_args_message = "Enter at least one application label." |
441 | 463 | |
| 464 | to_implement = 'handle_app_config' # Method to implement by subclass |
| 465 | |
442 | 466 | def add_arguments(self, parser): |
443 | 467 | parser.add_argument('args', metavar='app_label', nargs='+', |
444 | 468 | help='One or more application label.') |
… |
… |
class LabelCommand(BaseCommand):
|
481 | 505 | label = 'label' |
482 | 506 | missing_args_message = "Enter at least one %s." % label |
483 | 507 | |
| 508 | to_implement = 'handle_label' # Method to implement by subclass |
| 509 | |
484 | 510 | def add_arguments(self, parser): |
485 | 511 | parser.add_argument('args', metavar=self.label, nargs='+') |
486 | 512 | |