From e1d057d0cd0b84a55eded1899207e1f8a1c7589b 2013-03-04 23:03:35 From: MinRK Date: 2013-03-04 23:03:35 Subject: [PATCH] Backport PR #2663: Fix issue #2660: parsing of help and version arguments Help (-h --help --help-all) and version (--version -V) arguments that appear after a bare '--' argument are passed to the script IPython is running (like other arguments), instead of causing IPython itself to write out help / version info. --- diff --git a/IPython/config/application.py b/IPython/config/application.py index f9e94ee..8468b33 100644 --- a/IPython/config/application.py +++ b/IPython/config/application.py @@ -419,13 +419,22 @@ class Application(SingletonConfigurable): # it's a subcommand, and *not* a flag or class parameter return self.initialize_subcommand(subc, subargv) - if '-h' in argv or '--help' in argv or '--help-all' in argv: + # Arguments after a '--' argument are for the script IPython may be + # about to run, not IPython iteslf. For arguments parsed here (help and + # version), we want to only search the arguments up to the first + # occurrence of '--', which we're calling interpreted_argv. + try: + interpreted_argv = argv[:argv.index('--')] + except ValueError: + interpreted_argv = argv + + if any(x in interpreted_argv for x in ('-h', '--help-all', '--help')): self.print_description() - self.print_help('--help-all' in argv) + self.print_help('--help-all' in interpreted_argv) self.print_examples() self.exit(0) - if '--version' in argv or '-V' in argv: + if '--version' in interpreted_argv or '-V' in interpreted_argv: self.print_version() self.exit(0)