summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2008-08-08 13:40:11 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2008-08-08 13:40:11 +0000
commit9dfad9925718288bb81dbd6a50001767b6cc123d (patch)
tree950a29bacf2b27077fd1c661acd25e7d58f9db9a
parent196b2827759da3c80617418cbcdcb51f2d8ce1bc (diff)
Fixed #8120, #7997 -- Cleaned up the help messages displayed by django-admin so that the lax options aren't repeated, and the lax options are displayed when no subcommand is provided. Thanks to Scott Moonen <smoonen@andstuff.org> and trevor for the respective reports.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8228 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/management/__init__.py25
-rw-r--r--tests/regressiontests/admin_scripts/tests.py4
2 files changed, 23 insertions, 6 deletions
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index 1e8017e77f..d689199bc8 100644
--- a/django/core/management/__init__.py
+++ b/django/core/management/__init__.py
@@ -149,6 +149,21 @@ class LaxOptionParser(OptionParser):
def error(self, msg):
pass
+ def print_help(self):
+ """Output nothing.
+
+ The lax options are included in the normal option parser, so under
+ normal usage, we don't need to print the lax options.
+ """
+ pass
+
+ def print_lax_help(self):
+ """Output the basic options available to every command.
+
+ This just redirects to the default print_help() behaviour.
+ """
+ OptionParser.print_help(self)
+
def _process_args(self, largs, rargs, values):
"""
Overrides OptionParser._process_args to exclusively handle default
@@ -195,9 +210,7 @@ class ManagementUtility(object):
"""
Returns the script's main help text, as a string.
"""
- usage = ['%s <subcommand> [options] [args]' % self.prog_name]
- usage.append('Django command line tool, version %s' % django.get_version())
- usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name)
+ usage = ['',"Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,'']
usage.append('Available subcommands:')
commands = get_commands(self.user_commands, self.project_directory).keys()
commands.sort()
@@ -232,7 +245,9 @@ class ManagementUtility(object):
# Preprocess options to extract --settings and --pythonpath.
# These options could affect the commands that are available, so they
# must be processed early.
- parser = LaxOptionParser(version=get_version(), option_list=BaseCommand.option_list)
+ parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
+ version=get_version(),
+ option_list=BaseCommand.option_list)
try:
options, args = parser.parse_args(self.argv)
handle_default_options(options)
@@ -249,6 +264,7 @@ class ManagementUtility(object):
if len(args) > 2:
self.fetch_command(args[2]).print_help(self.prog_name, args[2])
else:
+ parser.print_lax_help()
sys.stderr.write(self.main_help_text() + '\n')
sys.exit(1)
# Special-cases: We want 'django-admin.py --version' and
@@ -257,6 +273,7 @@ class ManagementUtility(object):
# LaxOptionParser already takes care of printing the version.
pass
elif self.argv[1:] == ['--help']:
+ parser.print_lax_help()
sys.stderr.write(self.main_help_text() + '\n')
else:
self.fetch_command(subcommand).run_from_argv(self.argv)
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index 0c3fc1435e..9061f28d1e 100644
--- a/tests/regressiontests/admin_scripts/tests.py
+++ b/tests/regressiontests/admin_scripts/tests.py
@@ -894,9 +894,9 @@ class CommandTypes(AdminScriptTestCase):
args = ['--help']
out, err = self.run_manage(args)
if sys.version_info < (2, 5):
- self.assertOutput(out, "usage: manage.py [options]")
+ self.assertOutput(out, "usage: manage.py subcommand [options] [args]")
else:
- self.assertOutput(out, "Usage: manage.py [options]")
+ self.assertOutput(out, "Usage: manage.py subcommand [options] [args]")
self.assertOutput(err, "Type 'manage.py help <subcommand>' for help on a specific subcommand.")
def test_specific_help(self):