From e9e570aa0113c6faff98a9978a35f9821759ab4f Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Sun, 23 Jun 2019 03:41:39 +0200 Subject: [PATCH] Add cache list command This introduces a new cache sub-command that lists all available caches. Relates-to: #1162 --- docs/docs/cli.md | 12 ++++++++++++ poetry/console/commands/cache/cache.py | 3 ++- poetry/console/commands/cache/list.py | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 poetry/console/commands/cache/list.py diff --git a/docs/docs/cli.md b/docs/docs/cli.md index 717be699733..1f0d70b45a6 100644 --- a/docs/docs/cli.md +++ b/docs/docs/cli.md @@ -513,3 +513,15 @@ poetry env remove test-O3eWbxRl-py3.7 !!!note If your remove the currently activated virtualenv, it will be automatically deactivated. + +## cache + +The `cache` command regroups sub commands to interact with Poetry's cache. + +### cache list + +The `cache list` command lists Poetry's available caches. + +```bash +poetry cache list +``` diff --git a/poetry/console/commands/cache/cache.py b/poetry/console/commands/cache/cache.py index 9f80da7310d..b4c79fc19cc 100644 --- a/poetry/console/commands/cache/cache.py +++ b/poetry/console/commands/cache/cache.py @@ -1,3 +1,4 @@ +from poetry.console.commands.cache.list import CacheListCommand from ..command import Command from .clear import CacheClearCommand @@ -8,7 +9,7 @@ class CacheCommand(Command): name = "cache" description = "Interact with Poetry's cache" - commands = [CacheClearCommand()] + commands = [CacheClearCommand(), CacheListCommand()] def handle(self): return self.call("help", self._config.name) diff --git a/poetry/console/commands/cache/list.py b/poetry/console/commands/cache/list.py new file mode 100644 index 00000000000..52802eac7a3 --- /dev/null +++ b/poetry/console/commands/cache/list.py @@ -0,0 +1,24 @@ +import os + +from ..command import Command + + +class CacheListCommand(Command): + + name = "list" + description = "List Poetry's caches." + + def handle(self): + from poetry.locations import CACHE_DIR + from poetry.utils._compat import Path + + cache_dir = Path(CACHE_DIR) / "cache" / "repositories" + + if os.path.exists(str(cache_dir)): + caches = list(cache_dir.iterdir()) + if caches: + for cache in caches: + self.line("{}".format(cache.name)) + return 0 + + self.line("No caches found")