MCPcopy Index your code
hub / github.com/bpython/bpython / parse

Function parse

bpython/args.py:79–255  ·  view source on GitHub ↗

Receive an argument list - if None, use sys.argv - parse all args and take appropriate action. Also receive optional extra argument: this should be a tuple of (title, description, callback) title: The title for the argument group description: A full description of

(
    args: list[str] | None,
    extras: Options | None = None,
    ignore_stdin: bool = False,
)

Source from the content-addressed store, hash-verified

77
78
79def parse(
80 args: list[str] | None,
81 extras: Options | None = None,
82 ignore_stdin: bool = False,
83) -> tuple[Config, argparse.Namespace, list[str]]:
84 """Receive an argument list - if None, use sys.argv - parse all args and
85 take appropriate action. Also receive optional extra argument: this should
86 be a tuple of (title, description, callback)
87 title: The title for the argument group
88 description: A full description of the argument group
89 callback: A callback that adds argument to the argument group
90
91 e.g.:
92
93 def callback(group):
94 group.add_argument('-f', action='store_true', dest='f', help='Explode')
95 group.add_argument('-l', action='store_true', dest='l', help='Love')
96
97 parse(
98 ['-i', '-m', 'foo.py'],
99 (
100 'Front end-specific options',
101 'A full description of what these options are for',
102 callback
103 ),
104 )
105
106
107 Return a tuple of (config, options, exec_args) wherein "config" is the
108 config object either parsed from a default/specified config file or default
109 config options, "options" is the parsed options from
110 ArgumentParser.parse_args, and "exec_args" are the args (if any) to be parsed
111 to the executed file (if any).
112 """
113 if args is None:
114 args = sys.argv[1:]
115
116 parser = RaisingArgumentParser(
117 usage=_(
118 "Usage: %(prog)s [options] [file [args]]\n"
119 "NOTE: If bpython sees an argument it does "
120 "not know, execution falls back to the "
121 "regular Python interpreter."
122 )
123 )
124 parser.add_argument(
125 "--config",
126 default=default_config_path(),
127 type=Path,
128 help=_("Use CONFIG instead of default config file."),
129 )
130 parser.add_argument(
131 "--interactive",
132 "-i",
133 action="store_true",
134 help=_("Drop to bpython shell after running file instead of exiting."),
135 )
136 parser.add_argument(

Callers

nothing calls this directly

Calls 8

_Function · 0.90
default_config_pathFunction · 0.85
version_bannerFunction · 0.85
copyright_bannerFunction · 0.85
log_versionFunction · 0.85
ConfigClass · 0.85
isattyMethod · 0.45

Tested by

no test coverage detected