MCPcopy Create free account
hub / github.com/ipython/traitlets / parse_command_line

Method parse_command_line

traitlets/config/application.py:841–889  ·  view source on GitHub ↗

Parse the command line arguments.

(self, argv: ArgvType = None)

Source from the content-addressed store, hash-verified

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(

Callers 15

initializeMethod · 0.95
test_configMethod · 0.80
test_config_seq_argsMethod · 0.80
test_config_dict_argsMethod · 0.80
test_cli_priorityMethod · 0.80
test_cli_allow_noneMethod · 0.80
test_flagsMethod · 0.80
test_aliasesMethod · 0.80
test_aliases_multipleMethod · 0.80
test_flag_clobberMethod · 0.80

Calls 12

_get_sys_argvMethod · 0.95
initialize_subcommandMethod · 0.95
print_helpMethod · 0.95
exitMethod · 0.95
print_versionMethod · 0.95
flatten_flagsMethod · 0.95
_create_loaderMethod · 0.95
cast_unicodeFunction · 0.85
update_configMethod · 0.80
load_configMethod · 0.45

Tested by 15

test_configMethod · 0.64
test_config_seq_argsMethod · 0.64
test_config_dict_argsMethod · 0.64
test_cli_priorityMethod · 0.64
test_cli_allow_noneMethod · 0.64
test_flagsMethod · 0.64
test_aliasesMethod · 0.64
test_aliases_multipleMethod · 0.64
test_flag_clobberMethod · 0.64
test_extra_argsMethod · 0.64