From b740f9632600e1a26521afbef55b1e73410fa7b5 Mon Sep 17 00:00:00 2001 From: finswimmer Date: Sat, 15 Oct 2022 21:44:50 +0200 Subject: [PATCH 1/4] feat(cli): added cli option to specify path to project to run on --- src/poetry/console/application.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/poetry/console/application.py b/src/poetry/console/application.py index e54c679be9c..533233cadf3 100644 --- a/src/poetry/console/application.py +++ b/src/poetry/console/application.py @@ -121,8 +121,13 @@ def poetry(self) -> Poetry: if self._poetry is not None: return self._poetry + project_path = Path.cwd() + + if self._io and self._io.input.option("directory"): + project_path = self._io.input.option("directory") + self._poetry = Factory().create_poetry( - Path.cwd(), + cwd=project_path, io=self._io, disable_plugins=self._disable_plugins, disable_cache=self._disable_cache, @@ -367,6 +372,18 @@ def _default_definition(self) -> Definition: ) ) + definition.add_option( + Option( + "--directory", + "-C", + flag=False, + description=( + "The working directory for the Poetry command (defaults to the" + " current working directory)." + ), + ) + ) + return definition def _get_solution_provider_repository(self) -> SolutionProviderRepository: From 58abe88c9167c8641e501d1a264ab9e24dcba25f Mon Sep 17 00:00:00 2001 From: finswimmer Date: Sat, 15 Oct 2022 22:41:25 +0200 Subject: [PATCH 2/4] feat(cli): interpret --directory option for `init` as target folder --- src/poetry/console/commands/init.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/poetry/console/commands/init.py b/src/poetry/console/commands/init.py index af259f5c059..e34fa2a7d36 100644 --- a/src/poetry/console/commands/init.py +++ b/src/poetry/console/commands/init.py @@ -77,7 +77,17 @@ def handle(self) -> int: from poetry.layouts import layout from poetry.utils.env import SystemEnv - pyproject = PyProjectTOML(Path.cwd() / "pyproject.toml") + project_path = Path.cwd() + + if self.io.input.option("directory"): + project_path = Path(self.io.input.option("directory")) + if not project_path.exists() or not project_path.is_dir(): + self.line_error( + "The --directory path is not a directory." + ) + return 1 + + pyproject = PyProjectTOML(project_path / "pyproject.toml") if pyproject.file.exists(): if pyproject.is_poetry_project(): From 67c6962376595999d145138cfb144110ea9b85fa Mon Sep 17 00:00:00 2001 From: finswimmer Date: Sat, 15 Oct 2022 22:42:16 +0200 Subject: [PATCH 3/4] feat(cli): added warning about ignoring --directory when trying to apply `new` command --- src/poetry/console/commands/new.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/poetry/console/commands/new.py b/src/poetry/console/commands/new.py index cde571aa202..968a3a2a90b 100644 --- a/src/poetry/console/commands/new.py +++ b/src/poetry/console/commands/new.py @@ -34,6 +34,12 @@ def handle(self) -> int: from poetry.layouts import layout from poetry.utils.env import SystemEnv + if self.io.input.option("directory"): + self.line_error( + "--directory only makes sense with existing projects, and will" + " be ignored. You should consider the option --path instead." + ) + if self.option("src"): layout_cls = layout("src") else: From c3e48b2b0d9b8437d24ac624cdb6f22a1085eaac Mon Sep 17 00:00:00 2001 From: finswimmer Date: Sun, 16 Oct 2022 08:43:59 +0200 Subject: [PATCH 4/4] feat(cli): added --directory option to docs --- docs/cli.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/cli.md b/docs/cli.md index dee328483da..9a71e0e1b92 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -29,6 +29,7 @@ then `--help` combined with any of those can give you more information. * `--no-interaction (-n)`: Do not ask any interactive question. * `--no-plugins`: Disables plugins. * `--no-cache`: Disables Poetry source caches. +* `--directory=DIRECTORY (-C)`: The working directory for the Poetry command (defaults to the current working directory). ## new