diff --git a/poetry/console/application.py b/poetry/console/application.py index 3285e681c87..e2f9f3b6a3e 100644 --- a/poetry/console/application.py +++ b/poetry/console/application.py @@ -72,6 +72,7 @@ def _load() -> Type[Command]: "env use", # Plugin commands "plugin add", + "plugin remove", "plugin show", # Self commands "self update", diff --git a/poetry/console/commands/plugin/remove.py b/poetry/console/commands/plugin/remove.py new file mode 100644 index 00000000000..74f9cfc4222 --- /dev/null +++ b/poetry/console/commands/plugin/remove.py @@ -0,0 +1,74 @@ +import os + +from typing import TYPE_CHECKING +from typing import cast + +from cleo.helpers import argument +from cleo.helpers import option + +from poetry.console.commands.command import Command + + +if TYPE_CHECKING: + from poetry.console.commands.remove import RemoveCommand + + +class PluginRemoveCommand(Command): + + name = "plugin remove" + + description = "Removes installed plugins" + + arguments = [ + argument("plugins", "The names of the plugins to install.", multiple=True), + ] + + options = [ + option( + "dry-run", + None, + "Output the operations but do not execute anything (implicitly enables --verbose).", + ) + ] + + def handle(self) -> int: + from pathlib import Path + + from cleo.io.inputs.string_input import StringInput + from cleo.io.io import IO + + from poetry.console.application import Application + from poetry.factory import Factory + from poetry.repositories.installed_repository import InstalledRepository + from poetry.utils.env import EnvManager + + plugins = self.argument("plugins") + + system_env = EnvManager.get_system_env() + env_dir = Path( + os.getenv("POETRY_HOME") if os.getenv("POETRY_HOME") else system_env.path + ) + + # From this point forward, all the logic will be deferred to + # the remove command, by using the global `pyproject.toml` file. + application = cast("Application", self.application) + remove_command: "RemoveCommand" = cast( + "RemoveCommand", application.find("remove") + ) + # We won't go through the event dispatching done by the application + # so we need to configure the command manually + remove_command.set_poetry(Factory().create_poetry(env_dir)) + remove_command.set_env(system_env) + application._configure_installer(remove_command, self._io) + + argv = ["update"] + plugins + if self.option("dry-run"): + argv.append("--dry-run") + + return remove_command.run( + IO( + StringInput(" ".join(argv)), + self._io.output, + self._io.error_output, + ) + )