Initialize a subcommand with argv.
(self, subc: str, argv: ArgvType = None)
| 698 | |
| 699 | @catch_config_error |
| 700 | def initialize_subcommand(self, subc: str, argv: ArgvType = None) -> None: |
| 701 | """Initialize a subcommand with argv.""" |
| 702 | val = self.subcommands.get(subc) |
| 703 | assert val is not None |
| 704 | subapp, _ = val |
| 705 | |
| 706 | if isinstance(subapp, str): |
| 707 | subapp = import_item(subapp) |
| 708 | |
| 709 | # Cannot issubclass() on a non-type (SOhttp://stackoverflow.com/questions/8692430) |
| 710 | if isinstance(subapp, type) and issubclass(subapp, Application): |
| 711 | # Clear existing instances before... |
| 712 | self.__class__.clear_instance() |
| 713 | # instantiating subapp... |
| 714 | self.subapp = subapp.instance(parent=self) |
| 715 | elif callable(subapp): |
| 716 | # or ask factory to create it... |
| 717 | self.subapp = subapp(self) |
| 718 | else: |
| 719 | raise AssertionError("Invalid mappings for subcommand '%s'!" % subc) |
| 720 | |
| 721 | # ... and finally initialize subapp. |
| 722 | self.subapp.initialize(argv) |
| 723 | |
| 724 | def flatten_flags(self) -> tuple[dict[str, t.Any], dict[str, t.Any]]: |
| 725 | """Flatten flags and aliases for loaders, so cl-args override as expected. |
no test coverage detected