diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index 7638937..0cdfbef 100644
a
|
b
|
def call_command(name, *args, **options):
|
160 | 160 | |
161 | 161 | return klass.execute(*args, **defaults) |
162 | 162 | |
| 163 | |
163 | 164 | class LaxOptionParser(OptionParser): |
164 | 165 | """ |
165 | 166 | An option parser that doesn't raise any errors on unknown options. |
… |
… |
class LaxOptionParser(OptionParser):
|
167 | 168 | This is needed because the --settings and --pythonpath options affect |
168 | 169 | the commands (and thus the options) that are available to the user. |
169 | 170 | """ |
| 171 | def __init__(self, utility, **kwargs): |
| 172 | self.utility = utility |
| 173 | OptionParser.__init__(self, **kwargs) |
| 174 | |
170 | 175 | def error(self, msg): |
171 | 176 | pass |
172 | 177 | |
173 | 178 | def print_help(self): |
174 | | """Output nothing. |
175 | | |
176 | | The lax options are included in the normal option parser, so under |
177 | | normal usage, we don't need to print the lax options. |
178 | 179 | """ |
179 | | pass |
180 | | |
181 | | def print_lax_help(self): |
182 | | """Output the basic options available to every command. |
183 | | |
184 | | This just redirects to the default print_help() behavior. |
| 180 | Either output the general help or trigger the help output of any |
| 181 | subcommand. |
185 | 182 | """ |
186 | | OptionParser.print_help(self) |
| 183 | if len(self.largs) > 1 and self.largs[-1] != 'help': |
| 184 | # Calling help for subcommand instead |
| 185 | self.utility.fetch_command(self.largs[-1]).print_help(*self.largs) |
| 186 | else: |
| 187 | OptionParser.print_help(self) |
| 188 | sys.stdout.write(self.utility.main_help_text() + '\n') |
187 | 189 | |
188 | 190 | def _process_args(self, largs, rargs, values): |
189 | 191 | """ |
… |
… |
class LaxOptionParser(OptionParser):
|
211 | 213 | # dealing with options |
212 | 214 | del rargs[0] |
213 | 215 | raise Exception |
214 | | except: |
| 216 | except Exception: |
215 | 217 | largs.append(arg) |
216 | 218 | |
| 219 | |
217 | 220 | class ManagementUtility(object): |
218 | 221 | """ |
219 | 222 | Encapsulates the logic of the django-admin.py and manage.py utilities. |
… |
… |
class ManagementUtility(object):
|
355 | 358 | # Preprocess options to extract --settings and --pythonpath. |
356 | 359 | # These options could affect the commands that are available, so they |
357 | 360 | # must be processed early. |
358 | | parser = LaxOptionParser(usage="%prog subcommand [options] [args]", |
| 361 | parser = LaxOptionParser(self, |
| 362 | usage="%prog subcommand [options] [args]", |
359 | 363 | version=get_version(), |
360 | 364 | option_list=BaseCommand.option_list) |
361 | 365 | self.autocomplete() |
362 | | try: |
363 | | options, args = parser.parse_args(self.argv) |
364 | | handle_default_options(options) |
365 | | except: |
366 | | pass # Ignore any option errors at this point. |
| 366 | options, args = parser.parse_args(self.argv) |
| 367 | handle_default_options(options) |
367 | 368 | |
368 | 369 | try: |
369 | 370 | subcommand = self.argv[1] |
… |
… |
class ManagementUtility(object):
|
372 | 373 | |
373 | 374 | if subcommand == 'help': |
374 | 375 | if len(args) <= 2: |
375 | | parser.print_lax_help() |
376 | | sys.stdout.write(self.main_help_text() + '\n') |
| 376 | parser.print_help() |
377 | 377 | elif args[2] == '--commands': |
378 | 378 | sys.stdout.write(self.main_help_text(commands_only=True) + '\n') |
379 | 379 | else: |
380 | 380 | self.fetch_command(args[2]).print_help(self.prog_name, args[2]) |
381 | 381 | elif subcommand == 'version': |
382 | 382 | sys.stdout.write(parser.get_version() + '\n') |
383 | | # Special-cases: We want 'django-admin.py --version' and |
384 | | # 'django-admin.py --help' to work, for backwards compatibility. |
385 | | elif self.argv[1:] == ['--version']: |
386 | | # LaxOptionParser already takes care of printing the version. |
387 | | pass |
388 | | elif self.argv[1:] in (['--help'], ['-h']): |
389 | | parser.print_lax_help() |
390 | | sys.stdout.write(self.main_help_text() + '\n') |
391 | 383 | else: |
392 | 384 | self.fetch_command(subcommand).run_from_argv(self.argv) |
393 | 385 | |
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index baec168..d255318 100644
a
|
b
|
class CommandTypes(AdminScriptTestCase):
|
1217 | 1217 | "--version is equivalent to version" |
1218 | 1218 | args1, args2 = ['version'], ['--version'] |
1219 | 1219 | self.assertEqual(self.run_manage(args1), self.run_manage(args2)) |
| 1220 | # Whatever the accompanying command, --version always quit |
| 1221 | args3 = ['grumble', '--version'] |
| 1222 | self.assertEqual(self.run_manage(args1), self.run_manage(args3)) |
1220 | 1223 | |
1221 | 1224 | def test_help(self): |
1222 | 1225 | "help is handled as a special case" |