Commit ccfb87ae by Arun Babu Neelicattu

command options: allow for default values

parent a514831e
......@@ -107,7 +107,7 @@ You can specify a package in the following forms:
)
group = "dev"
else:
group = self.option("group")
group = self.option("group", self.default_group or MAIN_GROUP)
if self.option("extras") and len(packages) > 1:
raise ValueError(
......
from __future__ import annotations
from typing import TYPE_CHECKING
from typing import Any
from cleo.commands.command import Command as BaseCommand
from cleo.exceptions import ValueException
if TYPE_CHECKING:
......@@ -30,3 +32,9 @@ class Command(BaseCommand):
def reset_poetry(self) -> None:
self.get_application().reset_poetry()
def option(self, name: str, default: Any = None) -> Any:
try:
return super().option(name)
except ValueException:
return default
......@@ -61,6 +61,16 @@ class GroupCommand(EnvCommand):
}
@property
def default_group(self) -> str | None:
"""
The default group to use when no group is specified. This is useful
for command that have the `--group` option, eg: add, remove.
Can be overridden to adapt behavior.
"""
return None
@property
def default_groups(self) -> set[str]:
"""
The groups that are considered by the command by default.
......
......@@ -80,7 +80,7 @@ dependencies and not including the current project, run the command with the
)
extras = []
for extra in self.option("extras"):
for extra in self.option("extras", []):
if " " in extra:
extras += [e.strip() for e in extra.split(" ")]
else:
......
......@@ -48,7 +48,7 @@ list of installed packages
)
group = "dev"
else:
group = self.option("group")
group = self.option("group", self.default_group)
content = self.poetry.file.read()
poetry_content = content["tool"]["poetry"]
......@@ -106,7 +106,7 @@ list of installed packages
self.poetry.config.get("experimental.new-installer", False)
)
self._installer.dry_run(self.option("dry-run"))
self._installer.dry_run(self.option("dry-run", False))
self._installer.verbose(self._io.is_verbose())
self._installer.update(True)
self._installer.whitelist(removed_set)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment