Construct an argument parser using the function decorations.
(magic_func)
| 171 | |
| 172 | |
| 173 | def construct_parser(magic_func): |
| 174 | """ Construct an argument parser using the function decorations. |
| 175 | """ |
| 176 | kwds = getattr(magic_func, 'argcmd_kwds', {}) |
| 177 | if 'description' not in kwds: |
| 178 | kwds['description'] = getattr(magic_func, '__doc__', None) |
| 179 | arg_name = real_name(magic_func) |
| 180 | parser = MagicArgumentParser(arg_name, **kwds) |
| 181 | # Reverse the list of decorators in order to apply them in the |
| 182 | # order in which they appear in the source. |
| 183 | group = None |
| 184 | for deco in magic_func.decorators[::-1]: |
| 185 | result = deco.add_to_parser(parser, group) |
| 186 | if result is not None: |
| 187 | group = result |
| 188 | |
| 189 | # Replace the magic function's docstring with the full help text. |
| 190 | magic_func.__doc__ = parser.format_help() |
| 191 | |
| 192 | return parser |
| 193 | |
| 194 | |
| 195 | def parse_argstring(magic_func, argstring, *, partial=False): |
no test coverage detected
searching dependent graphs…