status: Support --json option
It's really simple to reflect the DBus API into JSON, which tools like Ansible or `jq` from the command line or whatever can parse to find interesting things like the current version. Closes: #301 Closes: #315 Approved by: jlebon
This commit is contained in:
parent
0578e13de8
commit
b7d1b827b7
@ -24,6 +24,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <glib-unix.h>
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#include "rpmostree-builtins.h"
|
||||
#include "rpmostree-dbus-helpers.h"
|
||||
@ -32,9 +33,11 @@
|
||||
#include <libglnx.h>
|
||||
|
||||
static gboolean opt_pretty;
|
||||
static gboolean opt_json;
|
||||
|
||||
static GOptionEntry option_entries[] = {
|
||||
{ "pretty", 'p', 0, G_OPTION_ARG_NONE, &opt_pretty, "This option is deprecated and no longer has any effect", NULL },
|
||||
{ "json", 0, 0, G_OPTION_ARG_NONE, &opt_json, "Output JSON", NULL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@ -240,10 +243,19 @@ rpmostree_builtin_status (int argc,
|
||||
deployments = rpmostree_sysroot_dup_deployments (sysroot_proxy);
|
||||
booted_deployment = rpmostree_os_dup_booted_deployment (os_proxy);
|
||||
|
||||
if (!status_generic (sysroot_proxy, os_proxy, deployments,
|
||||
booted_deployment,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
if (opt_json)
|
||||
{
|
||||
gsize len;
|
||||
g_autofree char *serialized = json_gvariant_serialize_data (deployments, &len);
|
||||
g_print ("%s\n", serialized);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!status_generic (sysroot_proxy, os_proxy, deployments,
|
||||
booted_deployment,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
exit_status = EXIT_SUCCESS;
|
||||
out:
|
||||
|
@ -43,6 +43,13 @@ rpm-ostree status | tee OUTPUT-status.txt
|
||||
assert_file_has_content OUTPUT-status.txt '1\.0\.10'
|
||||
echo "ok status shows right version"
|
||||
|
||||
rpm-ostree status --json > status.json
|
||||
json-glib-format status.json
|
||||
if test -x /usr/bin/jq; then
|
||||
jq '.[0].version' < status.json > version.txt
|
||||
assert_file_has_content version.txt '1\.0\.10'
|
||||
fi
|
||||
|
||||
os_repository_new_commit
|
||||
rpm-ostree upgrade --os=testos
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user