Construct an argument parser using the function decorations.
(magic_func)
| 137 | |
| 138 | |
| 139 | def construct_parser(magic_func): |
| 140 | """ Construct an argument parser using the function decorations. |
| 141 | """ |
| 142 | kwds = getattr(magic_func, 'argcmd_kwds', {}) |
| 143 | if 'description' not in kwds: |
| 144 | kwds['description'] = getattr(magic_func, '__doc__', None) |
| 145 | arg_name = real_name(magic_func) |
| 146 | parser = MagicArgumentParser(arg_name, **kwds) |
| 147 | # Reverse the list of decorators in order to apply them in the |
| 148 | # order in which they appear in the source. |
| 149 | group = None |
| 150 | for deco in magic_func.decorators[::-1]: |
| 151 | result = deco.add_to_parser(parser, group) |
| 152 | if result is not None: |
| 153 | group = result |
| 154 | |
| 155 | # Replace the magic function's docstring with the full help text. |
| 156 | magic_func.__doc__ = parser.format_help() |
| 157 | |
| 158 | return parser |
| 159 | |
| 160 | |
| 161 | def parse_argstring(magic_func, argstring): |
no test coverage detected