mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #1070 from cyxae/enh-app-search
Define a new "yunohost app search" command
This commit is contained in:
commit
bff5ad59dc
2 changed files with 24 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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...
|
||||
|
|
Loading…
Add table
Reference in a new issue