(parser, commonspecs, argspecs)
| 451 | |
| 452 | |
| 453 | def _add_cmd_cli(parser, commonspecs, argspecs): |
| 454 | processors = [] |
| 455 | argspecs = list(commonspecs or ()) + list(argspecs or ()) |
| 456 | for argspec in argspecs: |
| 457 | if callable(argspec): |
| 458 | procs = argspec(parser) |
| 459 | _add_procs(processors, procs) |
| 460 | else: |
| 461 | if not argspec: |
| 462 | raise NotImplementedError |
| 463 | args = list(argspec) |
| 464 | if not isinstance(args[-1], str): |
| 465 | kwargs = args.pop() |
| 466 | if not isinstance(args[0], str): |
| 467 | try: |
| 468 | args, = args |
| 469 | except (TypeError, ValueError): |
| 470 | parser.error(f'invalid cmd args {argspec!r}') |
| 471 | else: |
| 472 | kwargs = {} |
| 473 | parser.add_argument(*args, **kwargs) |
| 474 | # There will be nothing to process. |
| 475 | return processors |
| 476 | |
| 477 | |
| 478 | def _flatten_processors(processors): |
no test coverage detected
searching dependent graphs…