Ticket #11745: help-categories-with-colors.patch

File help-categories-with-colors.patch, 1.5 KB (added by Vlada Macek, 15 years ago)

Categorizes the commands in the "manage.py help" list

  • django/core/management/__init__.py

     
    55
    66import django
    77from django.core.management.base import BaseCommand, CommandError, handle_default_options
     8from django.core.management.color import color_style
    89from django.utils.importlib import import_module
    910
    1011# For backwards compatibility: get_version() used to be in this module.
     
    236237        """
    237238        usage = ['',"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,'']
    238239        usage.append('Available subcommands:')
    239         commands = get_commands().keys()
    240         commands.sort()
    241         for cmd in commands:
    242             usage.append('  %s' % cmd)
     240        commands_dict = {}
     241        style = color_style()
     242        for name, app in get_commands().iteritems():
     243            if isinstance(app, BaseCommand):
     244                app = app.__module__
     245            try:
     246                app = app.split('.')[0]
     247            except:
     248                pass
     249            if app not in commands_dict:
     250                commands_dict[app] = []
     251            commands_dict[app].append(name)
     252        for app in sorted(commands_dict.keys()):
     253            usage.append(style.NOTICE('\n[%s]' % app))
     254            for name in sorted(commands_dict[app]):
     255                usage.append('  %s' % name)
    243256        return '\n'.join(usage)
    244257
    245258    def fetch_command(self, subcommand):
Back to Top