From: Richard Hughes Date: Tue, 21 Feb 2023 10:13:29 +0000 (+0000) Subject: Allow filtering the output of get-devices by the device ID X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=15a1e61f845e9edbb5110bc59455bf039fb20ca7;p=fwupd.git Allow filtering the output of get-devices by the device ID This means you can print the one thing you care about. --- diff --git a/src/fu-tool.c b/src/fu-tool.c index 2ea5cbdda..c619f1b68 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -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); diff --git a/src/fu-util.c b/src/fu-util.c index 121528ebf..4ed2e18c5 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -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)