Commit f8ef8509 authored by Richard Hughes's avatar Richard Hughes
Browse files

Add --version option to fwupdmgr

    $ fwupdmgr --version
    client version:	0.9.6
    daemon version:	0.9.6

Fixes https://github.com/hughsie/fwupd/issues/153
parent 8ab4f403
...@@ -40,6 +40,7 @@ static void fwupd_client_finalize (GObject *object); ...@@ -40,6 +40,7 @@ static void fwupd_client_finalize (GObject *object);
typedef struct { typedef struct {
FwupdStatus status; FwupdStatus status;
guint percentage; guint percentage;
gchar *daemon_version;
GDBusConnection *conn; GDBusConnection *conn;
GDBusProxy *proxy; GDBusProxy *proxy;
} FwupdClientPrivate; } FwupdClientPrivate;
...@@ -57,6 +58,7 @@ enum { ...@@ -57,6 +58,7 @@ enum {
PROP_0, PROP_0,
PROP_STATUS, PROP_STATUS,
PROP_PERCENTAGE, PROP_PERCENTAGE,
PROP_DAEMON_VERSION,
PROP_LAST PROP_LAST
}; };
...@@ -97,6 +99,15 @@ fwupd_client_helper_new (void) ...@@ -97,6 +99,15 @@ fwupd_client_helper_new (void)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(FwupdClientHelper, fwupd_client_helper_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC(FwupdClientHelper, fwupd_client_helper_free)
static void
fwupd_client_set_daemon_version (FwupdClient *client, const gchar *daemon_version)
{
FwupdClientPrivate *priv = GET_PRIVATE (client);
g_free (priv->daemon_version);
priv->daemon_version = g_strdup (daemon_version);
g_object_notify (G_OBJECT (client), "daemon-version");
}
static void static void
fwupd_client_properties_changed_cb (GDBusProxy *proxy, fwupd_client_properties_changed_cb (GDBusProxy *proxy,
GVariant *changed_properties, GVariant *changed_properties,
...@@ -127,6 +138,12 @@ fwupd_client_properties_changed_cb (GDBusProxy *proxy, ...@@ -127,6 +138,12 @@ fwupd_client_properties_changed_cb (GDBusProxy *proxy,
g_object_notify (G_OBJECT (client), "percentage"); g_object_notify (G_OBJECT (client), "percentage");
} }
} }
if (g_variant_dict_contains (&dict, "DaemonVersion")) {
g_autoptr(GVariant) val = NULL;
val = g_dbus_proxy_get_cached_property (proxy, "DaemonVersion");
if (val != NULL)
fwupd_client_set_daemon_version (client, g_variant_get_string (val, NULL));
}
} }
static void static void
...@@ -185,6 +202,7 @@ gboolean ...@@ -185,6 +202,7 @@ gboolean
fwupd_client_connect (FwupdClient *client, GCancellable *cancellable, GError **error) fwupd_client_connect (FwupdClient *client, GCancellable *cancellable, GError **error)
{ {
FwupdClientPrivate *priv = GET_PRIVATE (client); FwupdClientPrivate *priv = GET_PRIVATE (client);
g_autoptr(GVariant) val = NULL;
g_return_val_if_fail (FWUPD_IS_CLIENT (client), FALSE); g_return_val_if_fail (FWUPD_IS_CLIENT (client), FALSE);
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
...@@ -212,6 +230,9 @@ fwupd_client_connect (FwupdClient *client, GCancellable *cancellable, GError **e ...@@ -212,6 +230,9 @@ fwupd_client_connect (FwupdClient *client, GCancellable *cancellable, GError **e
G_CALLBACK (fwupd_client_properties_changed_cb), client); G_CALLBACK (fwupd_client_properties_changed_cb), client);
g_signal_connect (priv->proxy, "g-signal", g_signal_connect (priv->proxy, "g-signal",
G_CALLBACK (fwupd_client_signal_cb), client); G_CALLBACK (fwupd_client_signal_cb), client);
val = g_dbus_proxy_get_cached_property (priv->proxy, "DaemonVersion");
if (val != NULL)
fwupd_client_set_daemon_version (client, g_variant_get_string (val, NULL));
return TRUE; return TRUE;
} }
...@@ -919,6 +940,24 @@ fwupd_client_get_percentage (FwupdClient *client) ...@@ -919,6 +940,24 @@ fwupd_client_get_percentage (FwupdClient *client)
return priv->percentage; return priv->percentage;
} }
/**
* fwupd_client_get_daemon_version:
* @client: A #FwupdClient
*
* Gets the daemon version number.
*
* Returns: a string, or %NULL for unknown.
*
* Since: 0.9.6
**/
const gchar *
fwupd_client_get_daemon_version (FwupdClient *client)
{
FwupdClientPrivate *priv = GET_PRIVATE (client);
g_return_val_if_fail (FWUPD_IS_CLIENT (client), NULL);
return priv->daemon_version;
}
/** /**
* fwupd_client_get_status: * fwupd_client_get_status:
* @client: A #FwupdClient * @client: A #FwupdClient
...@@ -1048,6 +1087,9 @@ fwupd_client_get_property (GObject *object, guint prop_id, ...@@ -1048,6 +1087,9 @@ fwupd_client_get_property (GObject *object, guint prop_id,
case PROP_PERCENTAGE: case PROP_PERCENTAGE:
g_value_set_uint (value, priv->percentage); g_value_set_uint (value, priv->percentage);
break; break;
case PROP_DAEMON_VERSION:
g_value_set_string (value, priv->daemon_version);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
...@@ -1190,6 +1232,17 @@ fwupd_client_class_init (FwupdClientClass *klass) ...@@ -1190,6 +1232,17 @@ fwupd_client_class_init (FwupdClientClass *klass)
0, 100, 0, 0, 100, 0,
G_PARAM_READWRITE); G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_PERCENTAGE, pspec); g_object_class_install_property (object_class, PROP_PERCENTAGE, pspec);
/**
* FwupdClient:daemon-version:
*
* The daemon version number.
*
* Since: 0.9.6
*/
pspec = g_param_spec_string ("daemon-version", NULL, NULL,
NULL, G_PARAM_READABLE);
g_object_class_install_property (object_class, PROP_DAEMON_VERSION, pspec);
} }
static void static void
...@@ -1203,6 +1256,7 @@ fwupd_client_finalize (GObject *object) ...@@ -1203,6 +1256,7 @@ fwupd_client_finalize (GObject *object)
FwupdClient *client = FWUPD_CLIENT (object); FwupdClient *client = FWUPD_CLIENT (object);
FwupdClientPrivate *priv = GET_PRIVATE (client); FwupdClientPrivate *priv = GET_PRIVATE (client);
g_free (priv->daemon_version);
if (priv->conn != NULL) if (priv->conn != NULL)
g_object_unref (priv->conn); g_object_unref (priv->conn);
if (priv->proxy != NULL) if (priv->proxy != NULL)
......
...@@ -104,6 +104,7 @@ gboolean fwupd_client_update_metadata (FwupdClient *client, ...@@ -104,6 +104,7 @@ gboolean fwupd_client_update_metadata (FwupdClient *client,
GError **error); GError **error);
FwupdStatus fwupd_client_get_status (FwupdClient *client); FwupdStatus fwupd_client_get_status (FwupdClient *client);
guint fwupd_client_get_percentage (FwupdClient *client); guint fwupd_client_get_percentage (FwupdClient *client);
const gchar *fwupd_client_get_daemon_version (FwupdClient *client);
G_END_DECLS G_END_DECLS
......
...@@ -1058,6 +1058,7 @@ main (int argc, char *argv[]) ...@@ -1058,6 +1058,7 @@ main (int argc, char *argv[])
gboolean offline = FALSE; gboolean offline = FALSE;
gboolean ret; gboolean ret;
gboolean verbose = FALSE; gboolean verbose = FALSE;
gboolean version = FALSE;
gint rc = 1; gint rc = 1;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autofree gchar *cmd_descriptions = NULL; g_autofree gchar *cmd_descriptions = NULL;
...@@ -1065,6 +1066,9 @@ main (int argc, char *argv[]) ...@@ -1065,6 +1066,9 @@ main (int argc, char *argv[])
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
/* TRANSLATORS: command line option */ /* TRANSLATORS: command line option */
_("Show extra debugging information"), NULL }, _("Show extra debugging information"), NULL },
{ "version", '\0', 0, G_OPTION_ARG_NONE, &version,
/* TRANSLATORS: command line option */
_("Show client and daemon versions"), NULL },
{ "offline", '\0', 0, G_OPTION_ARG_NONE, &offline, { "offline", '\0', 0, G_OPTION_ARG_NONE, &offline,
/* TRANSLATORS: command line option */ /* TRANSLATORS: command line option */
_("Schedule installation for next reboot when possible"), NULL }, _("Schedule installation for next reboot when possible"), NULL },
...@@ -1225,6 +1229,22 @@ main (int argc, char *argv[]) ...@@ -1225,6 +1229,22 @@ main (int argc, char *argv[])
g_signal_connect (priv->client, "notify::status", g_signal_connect (priv->client, "notify::status",
G_CALLBACK (fu_util_client_notify_cb), priv); G_CALLBACK (fu_util_client_notify_cb), priv);
/* just show versions and exit */
if (version) {
g_print ("client version:\t%i.%i.%i\n",
FWUPD_MAJOR_VERSION,
FWUPD_MINOR_VERSION,
FWUPD_MICRO_VERSION);
if (!fwupd_client_connect (priv->client, priv->cancellable, &error)) {
g_printerr ("Failed to connect to daemon: %s\n",
error->message);
return EXIT_FAILURE;
}
g_print ("daemon version:\t%s\n",
fwupd_client_get_daemon_version (priv->client));
return EXIT_SUCCESS;
}
/* run the specified command */ /* run the specified command */
ret = fu_util_run (priv, argv[1], (gchar**) &argv[2], &error); ret = fu_util_run (priv, argv[1], (gchar**) &argv[2], &error);
if (!ret) { if (!ret) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment