Parse the command line arguments.
(self, argv: ArgvType = None)
| 839 | |
| 840 | @catch_config_error |
| 841 | def parse_command_line(self, argv: ArgvType = None) -> None: |
| 842 | """Parse the command line arguments.""" |
| 843 | assert not isinstance(argv, str) |
| 844 | if argv is None: |
| 845 | argv = self._get_sys_argv(check_argcomplete=bool(self.subcommands))[1:] |
| 846 | self.argv = [cast_unicode(arg) for arg in argv] |
| 847 | |
| 848 | if argv and argv[0] == "help": |
| 849 | # turn `ipython help notebook` into `ipython notebook -h` |
| 850 | argv = argv[1:] + ["-h"] |
| 851 | |
| 852 | if self.subcommands and len(argv) > 0: |
| 853 | # we have subcommands, and one may have been specified |
| 854 | subc, subargv = argv[0], argv[1:] |
| 855 | if re.match(r"^\w(\-?\w)*$", subc) and subc in self.subcommands: |
| 856 | # it's a subcommand, and *not* a flag or class parameter |
| 857 | self._handle_argcomplete_for_subcommand() |
| 858 | return self.initialize_subcommand(subc, subargv) |
| 859 | |
| 860 | # Arguments after a '--' argument are for the script IPython may be |
| 861 | # about to run, not IPython iteslf. For arguments parsed here (help and |
| 862 | # version), we want to only search the arguments up to the first |
| 863 | # occurrence of '--', which we're calling interpreted_argv. |
| 864 | try: |
| 865 | interpreted_argv = argv[: argv.index("--")] |
| 866 | except ValueError: |
| 867 | interpreted_argv = argv |
| 868 | |
| 869 | if any(x in interpreted_argv for x in ("-h", "--help-all", "--help")): |
| 870 | self.print_help("--help-all" in interpreted_argv) |
| 871 | self.exit(0) |
| 872 | |
| 873 | if "--version" in interpreted_argv or "-V" in interpreted_argv: |
| 874 | self.print_version() |
| 875 | self.exit(0) |
| 876 | |
| 877 | # flatten flags&aliases, so cl-args get appropriate priority: |
| 878 | flags, aliases = self.flatten_flags() |
| 879 | classes = list(self._classes_with_config_traits()) |
| 880 | loader = self._create_loader(argv, aliases, flags, classes=classes) |
| 881 | try: |
| 882 | self.cli_config = deepcopy(loader.load_config()) |
| 883 | except SystemExit: |
| 884 | # traitlets 5: no longer print help output on error |
| 885 | # help output is huge, and comes after the error |
| 886 | raise |
| 887 | self.update_config(self.cli_config) |
| 888 | # store unparsed args in extra_args |
| 889 | self.extra_args = loader.extra_args |
| 890 | |
| 891 | @classmethod |
| 892 | def _load_config_files( |