Enable an installed plugin. Enabled plugins are loaded when ggshield starts and their features become available. Example: ggshield plugin enable tokenscanner
(ctx: click.Context, plugin_name: str, **kwargs: Any)
| 18 | @add_common_options() |
| 19 | @click.pass_context |
| 20 | def enable_cmd(ctx: click.Context, plugin_name: str, **kwargs: Any) -> None: |
| 21 | """ |
| 22 | Enable an installed plugin. |
| 23 | |
| 24 | Enabled plugins are loaded when ggshield starts and their |
| 25 | features become available. |
| 26 | |
| 27 | Example: |
| 28 | |
| 29 | ggshield plugin enable tokenscanner |
| 30 | """ |
| 31 | enterprise_config = EnterpriseConfig.load() |
| 32 | downloader = PluginDownloader() |
| 33 | |
| 34 | # Check if plugin is installed |
| 35 | if not downloader.is_installed(plugin_name): |
| 36 | # Check if it's available via entry point |
| 37 | from ggshield.core.plugin.loader import PluginLoader |
| 38 | |
| 39 | loader = PluginLoader(enterprise_config) |
| 40 | discovered = {p.name: p for p in loader.discover_plugins()} |
| 41 | |
| 42 | if plugin_name not in discovered: |
| 43 | ui.display_error(f"Plugin '{plugin_name}' is not installed") |
| 44 | ui.display_info("Use 'ggshield plugin install' to install it first") |
| 45 | ctx.exit(ExitCode.USAGE_ERROR) |
| 46 | |
| 47 | enterprise_config.enable_plugin(plugin_name) |
| 48 | enterprise_config.save() |
| 49 | |
| 50 | ui.display_info(f"Enabled plugin: {plugin_name}") |
| 51 | |
| 52 | |
| 53 | @click.command() |
nothing calls this directly
no test coverage detected