diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-02-07 18:46:29 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-02-07 18:46:29 +0000 |
| commit | 175e6d77df526dea1ade94661e487072e7c7cd88 (patch) | |
| tree | 01c72a224ff47c1f2944612ad46381337d72eda2 /django | |
| parent | 09ad6d1b88381497493120c4be882175c11a4bc8 (diff) | |
Fixed #11745 -- Grouped commands by application in the output of `manage.py help`. Made 'version' consistent with 'help' while I was in the area, and added tests. Thanks Jannis for the feedback and review.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17462 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/__init__.py | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index bb03082be0..6edfc1264c 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -1,3 +1,4 @@ +import collections import os import sys from optparse import OptionParser, NO_DEFAULT @@ -5,6 +6,7 @@ import imp import warnings from django.core.management.base import BaseCommand, CommandError, handle_default_options +from django.core.management.color import color_style from django.utils.importlib import import_module # For backwards compatibility: get_version() used to be in this module. @@ -209,16 +211,32 @@ class ManagementUtility(object): self.argv = argv or sys.argv[:] self.prog_name = os.path.basename(self.argv[0]) - def main_help_text(self): + def main_help_text(self, commands_only=False): """ Returns the script's main help text, as a string. """ - usage = ['',"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,''] - usage.append('Available subcommands:') - commands = get_commands().keys() - commands.sort() - for cmd in commands: - usage.append(' %s' % cmd) + if commands_only: + usage = sorted(get_commands().keys()) + else: + usage = [ + "", + "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name, + "", + "Available subcommands:", + ] + commands_dict = collections.defaultdict(lambda: []) + for name, app in get_commands().iteritems(): + if app == 'django.core': + app = 'django' + else: + app = app.rpartition('.')[-1] + commands_dict[app].append(name) + style = color_style() + for app in sorted(commands_dict.keys()): + usage.append("") + usage.append(style.NOTICE("[%s]" % app)) + for name in sorted(commands_dict[app]): + usage.append(" %s" % name) return '\n'.join(usage) def fetch_command(self, subcommand): @@ -340,12 +358,15 @@ class ManagementUtility(object): subcommand = 'help' # Display help if no arguments were given. if subcommand == 'help': - if len(args) > 2: - self.fetch_command(args[2]).print_help(self.prog_name, args[2]) - else: + if len(args) <= 2: parser.print_lax_help() sys.stdout.write(self.main_help_text() + '\n') - sys.exit(1) + elif args[2] == '--commands': + sys.stdout.write(self.main_help_text(commands_only=True) + '\n') + else: + self.fetch_command(args[2]).print_help(self.prog_name, args[2]) + elif subcommand == 'version': + sys.stdout.write(parser.get_version() + '\n') # Special-cases: We want 'django-admin.py --version' and # 'django-admin.py --help' to work, for backwards compatibility. elif self.argv[1:] == ['--version']: |
