[gnome-software: 5/25] gs-cmd: Use GsCategoryManager to find categories for get-category-apps




commit 3c14108023ea542bd633a25870282e3168ded2d2
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Feb 1 22:51:09 2021 +0000

    gs-cmd: Use GsCategoryManager to find categories for get-category-apps
    
    This introduces no functional changes.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-cmd.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/lib/gs-cmd.c b/lib/gs-cmd.c
index bc01c9533..fa9021165 100644
--- a/lib/gs-cmd.c
+++ b/lib/gs-cmd.c
@@ -632,17 +632,26 @@ main (int argc, char **argv)
                        }
                }
        } else if (argc == 3 && g_strcmp0 (argv[1], "get-category-apps") == 0) {
-               g_autoptr(GsCategory) category = NULL;
-               g_autoptr(GsCategory) parent = NULL;
+               g_autoptr(GsCategory) category_owned = NULL;
+               GsCategory *category = NULL;
                g_auto(GStrv) split = NULL;
+               GsCategoryManager *manager = gs_plugin_loader_get_category_manager (self->plugin_loader);
+
                split = g_strsplit (argv[2], "/", 2);
                if (g_strv_length (split) == 1) {
-                       category = gs_category_new (split[0]);
+                       category_owned = gs_category_manager_lookup (manager, split[0]);
+                       category = category_owned;
                } else {
-                       parent = gs_category_new (split[0]);
-                       category = gs_category_new (split[1]);
-                       gs_category_add_child (parent, category);
+                       g_autoptr(GsCategory) parent = gs_category_manager_lookup (manager, split[0]);
+                       if (parent != NULL)
+                               category = gs_category_find_child (parent, split[1]);
                }
+
+               if (category == NULL) {
+                       g_printerr ("Error: Could not find category ā€˜%sā€™\n", argv[2]);
+                       return EXIT_FAILURE;
+               }
+
                for (i = 0; i < repeat; i++) {
                        g_autoptr(GsPluginJob) plugin_job = NULL;
                        if (list != NULL)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]