Define a new "yunohost app search" command

This commit is contained in:
Dave 2020-11-02 15:30:23 +01:00
parent 4d494c7e7c
commit 6b04a4cae4
2 changed files with 24 additions and 0 deletions

View file

@ -569,6 +569,13 @@ app:
full: --with-categories
help: Also return a list of app categories
action: store_true
### app_search()
search:
action_help: Search installable apps
arguments:
string:
help: Return matching app name or description with "string"
fetchlist:
deprecated: true

View file

@ -104,6 +104,23 @@ def app_catalog(full=False, with_categories=False):
return {"apps": catalog["apps"]}
else:
return {"apps": catalog["apps"], "categories": catalog["categories"]}
def app_search(string):
"""
Return a dict of apps whose description or name match the search string
"""
# Retrieve a simple dict listing all apps
catalog_of_apps = app_catalog()
# Selecting apps according to a match in app name or description
for app in catalog_of_apps["apps"].items():
if not (re.search(string, app[0], flags=re.IGNORECASE) or
re.search(string, app[1]['description'], flags=re.IGNORECASE)):
del catalog_of_apps["apps"][app[0]]
return catalog_of_apps
# Old legacy function...