From 9fbd7fe65dbc62325c1c64b260b7bad69bd1af39 Mon Sep 17 00:00:00 2001 From: Daniel Campello Date: Mon, 28 Sep 2020 14:53:39 -0600 Subject: [PATCH] Allow to filter get-updates on device-id This change allows to get available updates for a given device. This is similar to what is done for the update and activate commands. --- data/bash-completion/fwupdmgr.in | 2 +- data/bash-completion/fwupdtool.in | 2 +- src/fu-tool.c | 24 ++++++++++++++++++++---- src/fu-util.c | 25 +++++++++++++++++++++---- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/data/bash-completion/fwupdmgr.in b/data/bash-completion/fwupdmgr.in index 0288c0d34..106a205a0 100644 --- a/data/bash-completion/fwupdmgr.in +++ b/data/bash-completion/fwupdmgr.in @@ -98,7 +98,7 @@ _fwupdmgr() esac case $command in - activate|clear-results|downgrade|get-releases|get-results|unlock|verify|verify-update) + activate|clear-results|downgrade|get-releases|get-results|unlock|verify|verify-update|get-updates) if [[ "$prev" = "$command" ]]; then _show_device_ids else diff --git a/data/bash-completion/fwupdtool.in b/data/bash-completion/fwupdtool.in index 6b46f51b4..7d062e46b 100644 --- a/data/bash-completion/fwupdtool.in +++ b/data/bash-completion/fwupdtool.in @@ -109,7 +109,7 @@ _fwupdtool() _show_modifiers fi ;; - attach|detach|activate|verify-update|reinstall) + attach|detach|activate|verify-update|reinstall|get-updates) if [[ "$prev" = "$command" ]]; then _show_device_ids #modifiers diff --git a/src/fu-tool.c b/src/fu-tool.c index f88cc461c..c97661e44 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -328,10 +328,26 @@ fu_util_get_updates (FuUtilPrivate *priv, gchar **values, GError **error) return FALSE; title = fu_util_get_tree_title (priv); - /* get devices from daemon */ - devices = fu_engine_get_devices (priv->engine, error); - if (devices == NULL) + /* parse arguments */ + if (g_strv_length (values) == 0) { + devices = fu_engine_get_devices (priv->engine, error); + if (devices == NULL) + return FALSE; + } else if (g_strv_length (values) == 1) { + FuDevice *device; + device = fu_engine_get_device_by_id (priv->engine, values[0], error); + if (device == NULL) + return FALSE; + devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + g_ptr_array_add (devices, device); + } else { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_INVALID_ARGS, + "Invalid arguments"); return FALSE; + } + fwupd_device_array_ensure_parents (devices); g_ptr_array_sort (devices, fu_util_sort_devices_by_flags_cb); for (guint i = 0; i < devices->len; i++) { @@ -2499,7 +2515,7 @@ main (int argc, char *argv[]) fu_util_get_history); fu_util_cmd_array_add (cmd_array, "get-updates,get-upgrades", - NULL, + "[DEVICE-ID|GUID]", /* TRANSLATORS: command description */ _("Gets the list of updates for connected hardware"), fu_util_get_updates); diff --git a/src/fu-util.c b/src/fu-util.c index b16ef7a4e..617d2c366 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -1376,10 +1376,27 @@ fu_util_get_updates (FuUtilPrivate *priv, gchar **values, GError **error) if (!fu_util_perhaps_refresh_remotes (priv, error)) return FALSE; - /* get devices from daemon */ - devices = fwupd_client_get_devices (priv->client, NULL, error); - if (devices == NULL) + /* handle both forms */ + if (g_strv_length (values) == 0) { + devices = fwupd_client_get_devices (priv->client, NULL, error); + if (devices == NULL) + return FALSE; + } else if (g_strv_length (values) == 1) { + FwupdDevice *device = fwupd_client_get_device_by_id (priv->client, + values[0], + NULL, + error); + if (device == NULL) + return FALSE; + devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); + g_ptr_array_add (devices, device); + } else { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_INVALID_ARGS, + "Invalid arguments"); return FALSE; + } g_ptr_array_sort (devices, fu_util_sort_devices_by_flags_cb); for (guint i = 0; i < devices->len; i++) { FwupdDevice *dev = g_ptr_array_index (devices, i); @@ -2601,7 +2618,7 @@ main (int argc, char *argv[]) fu_util_get_details); fu_util_cmd_array_add (cmd_array, "get-updates,get-upgrades", - NULL, + "[DEVICE-ID|GUID]", /* TRANSLATORS: command description */ _("Gets the list of updates for connected hardware"), fu_util_get_updates);