Skip to content

Commit

Permalink
feat(cli)!: rename --directory to --project
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Nov 6, 2024
1 parent aba510e commit 6c05c10
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
13 changes: 5 additions & 8 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,22 +360,19 @@ def _default_definition(self) -> Definition:

definition.add_option(
Option(
"--directory",
"-C",
"--project",
"-P",
flag=False,
description=(
"The working directory for the Poetry command (defaults to the"
" current working directory)."
),
description=("Run the command in the given project directory."),
)
)

return definition

@cached_property
def _directory(self) -> Path:
if self._io and self._io.input.option("directory"):
return Path(self._io.input.option("directory")).absolute()
if self._io and self._io.input.option("project"):
return Path(self._io.input.option("project")).absolute()
return Path.cwd()


Expand Down
8 changes: 3 additions & 5 deletions src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ def handle(self) -> int:

project_path = Path.cwd()

if self.io.input.option("directory"):
project_path = Path(self.io.input.option("directory"))
if self.io.input.option("project"):
project_path = Path(self.io.input.option("project"))
if not project_path.exists() or not project_path.is_dir():
self.line_error(
"<error>The --directory path is not a directory.</error>"
)
self.line_error("<error>The --project path is not a directory.</error>")
return 1

return self._init_pyproject(project_path=project_path)
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/console/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class NewCommand(InitCommand):
def handle(self) -> int:
from pathlib import Path

if self.io.input.option("directory"):
if self.io.input.option("project"):
self.line_error(
"<warning>--directory only makes sense with existing projects, and will"
"<warning>--project only makes sense with existing projects, and will"
" be ignored. You should consider the option --path instead.</warning>"
)

Expand Down
2 changes: 1 addition & 1 deletion tests/console/commands/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_build_relative_directory_src_layout(
# initializes Poetry before passing the directory.
app = Application()
tester = ApplicationTester(app)
tester.execute("build --directory .")
tester.execute("build --project .")

build_dir = tmp_project_path / "dist"

Expand Down

0 comments on commit 6c05c10

Please sign in to comment.