Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds --assume-yes to cache clear command to suppress prompts #6212

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adds --assume-yes to cache clear command to suppress prompts
colindean committed Aug 22, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 9da5ea31fd38bd6d2ae97c8ce2cea44475171c82
29 changes: 22 additions & 7 deletions src/poetry/console/commands/cache/clear.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,15 @@ class CacheClearCommand(Command):
description = "Clears Poetry's cache."

arguments = [argument("cache", description="The name of the cache to clear.")]
options = [option("all", description="Clear all entries in the cache.")]
options = [
option(long_name="all", description="Clear all entries in the cache."),
option(
long_name="assume-yes",
short_name="y",
flag=True,
description="Assume yes; skip confirmation prompts",
),
]

def handle(self) -> int:
from cachy import CacheManager
@@ -55,11 +63,15 @@ def handle(self) -> int:
len(files) for _path, _dirs, files in os.walk(str(cache_dir))
)

delete = self.confirm(f"<question>Delete {entries_count} entries?</>")
if not delete:
return 0
if self.option("assume-yes"):
self.line(f"Deleting {entries_count} entries.")
else:
delete = self.confirm(f"<question>Delete {entries_count} entries?</>")
if not delete:
return 0

cache.flush()

elif len(parts) == 2:
raise RuntimeError(
"Only specifying the package name is not yet supported. "
@@ -73,9 +85,12 @@ def handle(self) -> int:
self.line(f"No cache entries for {package}:{version}")
return 0

delete = self.confirm(f"Delete cache entry {package}:{version}")
if not delete:
return 0
if self.option("assume-yes"):
self.line(f"Deleting cache entry {package}:{version}")
else:
delete = self.confirm(f"Delete cache entry {package}:{version}")
if not delete:
return 0

cache.forget(f"{package}:{version}")
else:
29 changes: 29 additions & 0 deletions tests/console/commands/cache/test_clear.py
Original file line number Diff line number Diff line change
@@ -39,6 +39,22 @@ def test_cache_clear_all(
assert not cache.has("cleo:0.2")


def test_cache_clear_all_assume_yes(
tester: ApplicationTester,
repository_one: str,
repository_cache_dir: Path,
cache: CacheManager,
):
exit_code = tester.execute(f"cache clear {repository_one} --all --assume-yes")

assert exit_code == 0
assert tester.io.fetch_output() == "Deleting 2 entries.\n"
# ensure directory is empty
assert not any((repository_cache_dir / repository_one).iterdir())
assert not cache.has("cachy:0.1")
assert not cache.has("cleo:0.2")


def test_cache_clear_all_no(
tester: ApplicationTester,
repository_one: str,
@@ -68,6 +84,19 @@ def test_cache_clear_pkg(
assert cache.has("cleo:0.2")


def test_cache_clear_pkg_assume_yes(
tester: ApplicationTester,
repository_one: str,
cache: CacheManager,
):
exit_code = tester.execute(f"cache clear {repository_one}:cachy:0.1 -y")

assert exit_code == 0
assert tester.io.fetch_output() == "Deleting cache entry cachy:0.1\n"
assert not cache.has("cachy:0.1")
assert cache.has("cleo:0.2")


def test_cache_clear_pkg_no(
tester: ApplicationTester,
repository_one: str,