summaryrefslogtreecommitdiff
path: root/client/as-util.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-08-25 14:20:18 +0100
committerRichard Hughes <richard@hughsie.com>2016-08-25 14:56:58 +0100
commitd0ebe1ee16a018575da1db056fdb128be95970e1 (patch)
treeacd68954fd66b7835d59eabdfaa2e47b0d0f5e68 /client/as-util.c
parentff63aa5a99f523fe900188cb34b3d9faac231125 (diff)
downloadappstream-glib-d0ebe1ee16a018575da1db056fdb128be95970e1.tar.gz
trivial: Add a query-installed command to appstream-util
Diffstat (limited to 'client/as-util.c')
-rw-r--r--client/as-util.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/client/as-util.c b/client/as-util.c
index 61eb14b..00a99dd 100644
--- a/client/as-util.c
+++ b/client/as-util.c
@@ -1378,6 +1378,59 @@ as_util_search_category (AsUtilPrivate *priv, gchar **values, GError **error)
return TRUE;
}
+static gboolean
+as_util_query_installed (AsUtilPrivate *priv, gchar **values, GError **error)
+{
+ AsApp *app;
+ GPtrArray *array;
+ guint i;
+ g_autoptr(AsStore) store = NULL;
+
+ /* load system database */
+ store = as_store_new ();
+ as_store_set_add_flags (store,
+ AS_STORE_ADD_FLAG_USE_UNIQUE_ID |
+ AS_STORE_ADD_FLAG_USE_MERGE_HEURISTIC);
+ 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_DESKTOP,
+ NULL, error))
+ return FALSE;
+
+ /* add matches to an array */
+ array = as_store_get_apps (store);
+ for (i = 0; i < array->len; i++) {
+ app = g_ptr_array_index (array, i);
+ if (as_app_get_state (app) != AS_APP_STATE_INSTALLED)
+ continue;
+ g_print ("%s\n", as_app_get_unique_id (app));
+ }
+
+ /* dump XML */
+ if (priv->verbose) {
+ g_autoptr(GString) xml = NULL;
+ g_autoptr(AsStore) store_results = as_store_new ();
+ as_store_set_add_flags (store_results,
+ AS_STORE_ADD_FLAG_USE_UNIQUE_ID);
+ for (i = 0; i < array->len; i++) {
+ app = g_ptr_array_index (array, i);
+ if (as_app_get_state (app) != AS_APP_STATE_INSTALLED)
+ continue;
+ as_store_add_app (store_results, app);
+ }
+ xml = as_store_to_xml (store_results,
+ AS_NODE_TO_XML_FLAG_ADD_HEADER |
+ AS_NODE_TO_XML_FLAG_FORMAT_INDENT |
+ AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE);
+ g_print ("%s\n", xml->str);
+ }
+
+ return TRUE;
+}
+
static gint
as_util_search_token_sort_cb (gconstpointer a, gconstpointer b, gpointer user_data)
{
@@ -3981,6 +4034,12 @@ main (int argc, char *argv[])
_("Search for AppStream applications by package name"),
as_util_search_pkgname);
as_util_add (priv->cmd_array,
+ "query-installed",
+ NULL,
+ /* TRANSLATORS: command description */
+ _("Show all installed AppStream applications"),
+ as_util_query_installed);
+ as_util_add (priv->cmd_array,
"search-category",
NULL,
/* TRANSLATORS: command description */