Skip to content
Merged
Changes from 3 commits
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
23 changes: 22 additions & 1 deletion examples/extensions/commands/clean/cmd_clean.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
from conan.api.conan_api import ConanAPI
from conan.internal.conan_app import ConanBasicApp
from conan.api.input import UserInput
from conan.api.output import ConanOutput, Color
from conan.cli.command import OnceArgument, conan_command

recipe_color = Color.BRIGHT_BLUE
removed_color = Color.BRIGHT_YELLOW

def _search_recipes(app, query: str, remote=None):
""""
Searches recipes in local cache or in a remote.
Extracted from conan/api/subapi/list.py
"""
only_none_user_channel = False
if query and query.endswith("@"):
only_none_user_channel = True
query = query[:-1]

if remote:
refs = app.remote_manager.search_recipes(remote, query)
else:
refs = app.cache.search_recipes(query)
ret = []
for r in refs:
if not only_none_user_channel or (r.user is None and r.channel is None):
ret.append(r)
return sorted(ret)

@conan_command(group="Custom commands")
def clean(conan_api: ConanAPI, parser, *args):
Expand All @@ -28,7 +48,8 @@ def confirmation(message):
output_remote = remote or "Local cache"

# Getting all the recipes
recipes = conan_api.search.recipes("*/*", remote=remote)
conan_app - ConanBasicApp(conan_api)
recipes = _search_recipes(conan_app, "*/*", remote=remote)
if recipes and not confirmation("Do you want to remove all the recipes revisions and their packages ones, "
"except the latest package revision from the latest recipe one?"):
return
Expand Down