Ticket #11745: 11745-2.patch

File 11745-2.patch, 8.2 KB (added by Aymeric Augustin, 13 years ago)
  • docs/releases/1.4.txt

     
    989989subclassing ``DjangoTestRunner`` and overriding its ``teardown_databases()``
    990990method.
    991991
     992Output of :djadmin:`manage.py help <help>`
     993~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     994
     995:djadmin:`manage.py help <help>` now groups available commands by application.
     996If you depended on its output, for instance if you parsed it, you must update
     997your scripts. To obtain the list of all available management commands in a
     998script, you can use :djadmin:`manage.py help --commands <help>` instead.
     999
    9921000Features deprecated in 1.4
    9931001==========================
    9941002
  • docs/ref/django-admin.txt

     
    4747Getting runtime help
    4848--------------------
    4949
    50 .. django-admin-option:: --help
     50.. django-admin:: help
    5151
    52 Run ``django-admin.py help`` to display a list of all available commands.
    53 Run ``django-admin.py help <command>`` to display a description of the
    54 given command and a list of its available options.
     52Run ``django-admin.py help`` to display usage information and a list of the
     53commands provided by each application.
    5554
     55Run ``django-admin.py help --commands`` to display a list of all available
     56commands.
     57
     58Run ``django-admin.py help <command>`` to display a description of the given
     59command and a list of its available options.
     60
    5661App names
    5762---------
    5863
     
    6368Determining the version
    6469-----------------------
    6570
    66 .. django-admin-option:: --version
     71.. django-admin:: version
    6772
    68 Run ``django-admin.py --version`` to display the current Django version.
     73Run ``django-admin.py version`` to display the current Django version.
    6974
    7075Examples of output::
    7176
  • tests/regressiontests/admin_scripts/tests.py

     
    173173        "Utility assertion: assert that the given message exists in the output"
    174174        self.assertTrue(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream))
    175175
     176    def assertNotInOutput(self, stream, msg):
     177        "Utility assertion: assert that the given message doesn't exist in the output"
     178        self.assertFalse(msg in stream, "'%s' matches actual output text '%s'" % (msg, stream))
     179
    176180##########################################################################
    177181# DJANGO ADMIN TESTS
    178182# This first series of test classes checks the environment processing
     
    11731177        self.remove_settings('settings.py')
    11741178
    11751179    def test_version(self):
    1176         "--version is handled as a special case"
    1177         args = ['--version']
     1180        "version is handled as a special case"
     1181        args = ['version']
    11781182        out, err = self.run_manage(args)
    11791183        self.assertNoOutput(err)
    11801184        self.assertOutput(out, get_version())
    11811185
     1186    def test_version_alternative(self):
     1187        "--version is equivalent to version"
     1188        args1, args2 = ['version'], ['--version']
     1189        self.assertEqual(self.run_manage(args1), self.run_manage(args2))
     1190
    11821191    def test_help(self):
    1183         "--help is handled as a special case"
    1184         args = ['--help']
     1192        "help is handled as a special case"
     1193        args = ['help']
    11851194        out, err = self.run_manage(args)
    11861195        self.assertOutput(out, "Usage: manage.py subcommand [options] [args]")
    11871196        self.assertOutput(out, "Type 'manage.py help <subcommand>' for help on a specific subcommand.")
     1197        self.assertOutput(out, '[django]')
     1198        self.assertOutput(out, 'startapp')
     1199        self.assertOutput(out, 'startproject')
    11881200
    1189     def test_short_help(self):
    1190         "-h is handled as a short form of --help"
    1191         args = ['-h']
     1201    def test_help_commands(self):
     1202        "help --commands shows the list of all available commands"
     1203        args = ['help', '--commands']
    11921204        out, err = self.run_manage(args)
    1193         self.assertOutput(out, "Usage: manage.py subcommand [options] [args]")
    1194         self.assertOutput(out, "Type 'manage.py help <subcommand>' for help on a specific subcommand.")
     1205        self.assertNotInOutput(out, 'Usage:')
     1206        self.assertNotInOutput(out, 'Options:')
     1207        self.assertNotInOutput(out, '[django]')
     1208        self.assertOutput(out, 'startapp')
     1209        self.assertOutput(out, 'startproject')
     1210        self.assertNotInOutput(out, '\n\n')
    11951211
     1212    def test_help_alternative(self):
     1213        "--help is equivalent to help"
     1214        args1, args2 = ['help'], ['--help']
     1215        self.assertEqual(self.run_manage(args1), self.run_manage(args2))
     1216
     1217    def test_help_short_altert(self):
     1218        "-h is handled as a short form of --help"
     1219        args1, args2 = ['--help'], ['-h']
     1220        self.assertEqual(self.run_manage(args1), self.run_manage(args2))
     1221
    11961222    def test_specific_help(self):
    11971223        "--help can be used on a specific command"
    11981224        args = ['sqlall', '--help']
  • django/core/management/__init__.py

     
     1import collections
    12import os
    23import sys
    34from optparse import OptionParser, NO_DEFAULT
     
    56import warnings
    67
    78from django.core.management.base import BaseCommand, CommandError, handle_default_options
     9from django.core.management.color import color_style
    810from django.utils.importlib import import_module
    911
    1012# For backwards compatibility: get_version() used to be in this module.
     
    209211        self.argv = argv or sys.argv[:]
    210212        self.prog_name = os.path.basename(self.argv[0])
    211213
    212     def main_help_text(self):
     214    def main_help_text(self, commands_only=False):
    213215        """
    214216        Returns the script's main help text, as a string.
    215217        """
    216         usage = ['',"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,'']
    217         usage.append('Available subcommands:')
    218         commands = get_commands().keys()
    219         commands.sort()
    220         for cmd in commands:
    221             usage.append('  %s' % cmd)
     218        if commands_only:
     219            usage = sorted(get_commands().keys())
     220        else:
     221            usage = [
     222                "",
     223                "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,
     224                "",
     225                "Available subcommands:",
     226            ]
     227            commands_dict = collections.defaultdict(lambda: [])
     228            for name, app in get_commands().iteritems():
     229                if app == 'django.core':
     230                    app = 'django'
     231                else:
     232                    app = app.rpartition('.')[-1]
     233                commands_dict[app].append(name)
     234            style = color_style()
     235            for app in sorted(commands_dict.keys()):
     236                usage.append("")
     237                usage.append(style.NOTICE("[%s]" % app))
     238                for name in sorted(commands_dict[app]):
     239                    usage.append("    %s" % name)
    222240        return '\n'.join(usage)
    223241
    224242    def fetch_command(self, subcommand):
     
    340358            subcommand = 'help' # Display help if no arguments were given.
    341359
    342360        if subcommand == 'help':
    343             if len(args) > 2:
    344                 self.fetch_command(args[2]).print_help(self.prog_name, args[2])
    345             else:
     361            if len(args) <= 2:
    346362                parser.print_lax_help()
    347363                sys.stdout.write(self.main_help_text() + '\n')
    348                 sys.exit(1)
     364            elif args[2] == '--commands':
     365                sys.stdout.write(self.main_help_text(commands_only=True) + '\n')
     366            else:
     367                self.fetch_command(args[2]).print_help(self.prog_name, args[2])
     368        elif subcommand == 'version':
     369            sys.stdout.write(parser.get_version() + '\n')
    349370        # Special-cases: We want 'django-admin.py --version' and
    350371        # 'django-admin.py --help' to work, for backwards compatibility.
    351372        elif self.argv[1:] == ['--version']:
Back to Top