-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
) |