Code

Ticket #16445: better_help_patch.patch

File better_help_patch.patch, 1.7 KB (added by mariarchi, 3 years ago)
  • django/core/management/__init__.py

    diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
    index 1345eaf..abad884 100644
    a b import os 
    22import sys 
    33from optparse import OptionParser, NO_DEFAULT 
    44import imp 
     5from collections import defaultdict 
    56 
    67import django 
    78from django.core.management.base import BaseCommand, CommandError, handle_default_options 
    class ManagementUtility(object): 
    233234    def main_help_text(self): 
    234235        """ 
    235236        Returns the script's main help text, as a string. 
    236         """ 
     237        """         
     238        from django.core.management.commands.startapp import ProjectCommand 
    237239        usage = ['',"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,''] 
    238240        usage.append('Available subcommands:') 
    239         commands = get_commands().keys() 
    240         commands.sort() 
    241         for cmd in commands: 
    242             usage.append('  %s' % cmd) 
     241         
     242        apps_to_commands = defaultdict(lambda: []) 
     243        for command, app in get_commands().items(): 
     244            # 'startapp' command is mapped to ProjectCommand 
     245            # instead of 'django.core'. 
     246            if isinstance(app, ProjectCommand): 
     247                app = 'django.core' 
     248            apps_to_commands[app].append(command) 
     249 
     250        for app in sorted(apps_to_commands.keys()): 
     251            usage.append("%s:" % app) 
     252            for command in sorted(apps_to_commands[app]): 
     253                usage.append("\t%s" % command) 
     254            usage.append("") # Extra newline separaing apps. 
     255 
    243256        return '\n'.join(usage) 
    244257 
    245258    def fetch_command(self, subcommand):