]> git.proxmox.com Git - fwupd.git/commitdiff
Allow filtering the output of get-devices by the device ID
authorRichard Hughes <richard@hughsie.com>
Tue, 21 Feb 2023 10:13:29 +0000 (10:13 +0000)
committerMario Limonciello <mario.limonciello@amd.com>
Thu, 23 Feb 2023 19:04:12 +0000 (13:04 -0600)
This means you can print the one thing you care about.

src/fu-tool.c
src/fu-util.c

index 2ea5cbddaa07a49afe6b4e07ca8c7d730b6200a2..c619f1b68b4c02c703922d19b7d105dc9d3c4fb9 100644 (file)
@@ -811,9 +811,20 @@ fu_util_get_devices(FuUtilPrivate *priv, gchar **values, GError **error)
                return FALSE;
 
        /* get devices and build tree */
-       devs = fu_engine_get_devices(priv->engine, error);
-       if (devs == NULL)
-               return FALSE;
+       if (g_strv_length(values) > 0) {
+               devs = g_ptr_array_new_with_free_func((GDestroyNotify)g_object_unref);
+               for (guint i = 0; values[i] != NULL; i++) {
+                       FuDevice *device = fu_util_get_device(priv, values[i], error);
+                       if (device == NULL)
+                               return FALSE;
+                       g_ptr_array_add(devs, device);
+               }
+       } else {
+               devs = fu_engine_get_devices(priv->engine, error);
+               if (devs == NULL)
+                       return FALSE;
+       }
+
        if (devs->len > 0) {
                fwupd_device_array_ensure_parents(devs);
                fu_util_build_device_tree(priv, root, devs, NULL);
index 121528ebf72f7e77a13c40db7feb433d7478abaa..4ed2e18c523869cdd79ff68a0263fc058aed21e3 100644 (file)
@@ -577,9 +577,19 @@ fu_util_get_devices(FuUtilPrivate *priv, gchar **values, GError **error)
        g_autoptr(GPtrArray) devs = NULL;
 
        /* get results from daemon */
-       devs = fwupd_client_get_devices(priv->client, priv->cancellable, error);
-       if (devs == NULL)
-               return FALSE;
+       if (g_strv_length(values) > 0) {
+               devs = g_ptr_array_new_with_free_func((GDestroyNotify)g_object_unref);
+               for (guint i = 0; values[i] != NULL; i++) {
+                       FwupdDevice *device = fu_util_get_device_by_id(priv, values[i], error);
+                       if (device == NULL)
+                               return FALSE;
+                       g_ptr_array_add(devs, device);
+               }
+       } else {
+               devs = fwupd_client_get_devices(priv->client, priv->cancellable, error);
+               if (devs == NULL)
+                       return FALSE;
+       }
 
        /* not for human consumption */
        if (priv->as_json)