Skip to content

Commit

Permalink
Add a plugin remove command
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Mar 10, 2021
1 parent c8fccd3 commit 65a2219
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def _load() -> Type[Command]:
"env use",
# Plugin commands
"plugin add",
"plugin remove",
"plugin show",
# Self commands
"self update",
Expand Down
74 changes: 74 additions & 0 deletions poetry/console/commands/plugin/remove.py
Original file line number Diff line number Diff line change
@@ -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,
)
)

0 comments on commit 65a2219

Please sign in to comment.