Merge pull request #1070 from cyxae/enh-app-search

Define a new "yunohost app search" command
This commit is contained in:
Alexandre Aubin 2021-01-24 05:04:13 +01:00 committed by GitHub
commit bff5ad59dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -581,6 +581,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...