diff options
author | Richard Hughes <richard@hughsie.com> | 2016-04-07 11:42:21 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-04-07 11:42:21 +0100 |
commit | dac9b7bc0a89391f22715f575dbdebfa14e691df (patch) | |
tree | 9d1638738c9895e9a0ecf2912624208802cba206 /client | |
parent | a2f5a2c88b16763be986389be85862ba851bd18e (diff) | |
download | appstream-glib-dac9b7bc0a89391f22715f575dbdebfa14e691df.tar.gz |
Add search-pkgname to appstream-glib
Diffstat (limited to 'client')
-rw-r--r-- | client/as-util.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/client/as-util.c b/client/as-util.c index 18976bb..c8c959a 100644 --- a/client/as-util.c +++ b/client/as-util.c @@ -1310,6 +1310,49 @@ as_util_search (AsUtilPrivate *priv, gchar **values, GError **error) } /** + * as_util_search_pkgname: + **/ +static gboolean +as_util_search_pkgname (AsUtilPrivate *priv, gchar **values, GError **error) +{ + AsApp *app; + guint i; + g_autoptr(AsStore) store = NULL; + + /* check args */ + if (g_strv_length (values) < 1) { + g_set_error_literal (error, + AS_ERROR, + AS_ERROR_INVALID_ARGUMENTS, + "Not enough arguments, " + "expected search terms"); + return FALSE; + } + + /* load system database */ + store = as_store_new (); + if (!as_store_load (store, + AS_STORE_LOAD_FLAG_IGNORE_INVALID | + AS_STORE_LOAD_FLAG_APP_INFO_SYSTEM | + AS_STORE_LOAD_FLAG_APP_INFO_USER | + AS_STORE_LOAD_FLAG_APPDATA | + AS_STORE_LOAD_FLAG_XDG_APP_USER | + AS_STORE_LOAD_FLAG_XDG_APP_SYSTEM | + AS_STORE_LOAD_FLAG_DESKTOP, + NULL, error)) + return FALSE; + + /* find by source */ + for (i = 0; values[i] != NULL; i++) { + app = as_store_get_app_by_pkgname (store, values[i]); + if (app == NULL) + continue; + g_print ("%s\n", as_app_get_id (app)); + } + return TRUE; +} + +/** * as_util_search_token_sort_cb: **/ static gint @@ -4048,6 +4091,12 @@ main (int argc, char *argv[]) _("Search for AppStream applications"), as_util_search); as_util_add (priv->cmd_array, + "search-pkgname", + NULL, + /* TRANSLATORS: command description */ + _("Search for AppStream applications by package name"), + as_util_search_pkgname); + as_util_add (priv->cmd_array, "show-search-tokens", NULL, /* TRANSLATORS: command description */ |