(self, ctx: click.Context, name: str)
| 615 | self._loaded_plugin_commands = True |
| 616 | |
| 617 | def get_command(self, ctx: click.Context, name: str) -> click.Command | None: |
| 618 | self._load_plugin_commands() |
| 619 | # Look up built-in and plugin commands, which should be |
| 620 | # available even if the app fails to load. |
| 621 | rv = super().get_command(ctx, name) |
| 622 | |
| 623 | if rv is not None: |
| 624 | return rv |
| 625 | |
| 626 | info = ctx.ensure_object(ScriptInfo) |
| 627 | |
| 628 | # Look up commands provided by the app, showing an error and |
| 629 | # continuing if the app couldn't be loaded. |
| 630 | try: |
| 631 | app = info.load_app() |
| 632 | except NoAppException as e: |
| 633 | click.secho(f"Error: {e.format_message()}\n", err=True, fg="red") |
| 634 | return None |
| 635 | |
| 636 | # Push an app context for the loaded app unless it is already |
| 637 | # active somehow. This makes the context available to parameter |
| 638 | # and command callbacks without needing @with_appcontext. |
| 639 | if not current_app or current_app._get_current_object() is not app: # type: ignore[attr-defined] |
| 640 | ctx.with_resource(app.app_context()) |
| 641 | |
| 642 | return app.cli.get_command(ctx, name) |
| 643 | |
| 644 | def list_commands(self, ctx: click.Context) -> list[str]: |
| 645 | self._load_plugin_commands() |
nothing calls this directly
no test coverage detected