app/status: Add --pending-exit-77 switch
This makes it easier for scripts to determine whether there is a pending deployment instead of using `--json/--jsonpath`. Closes: #1478 Approved by: cgwalters
This commit is contained in:
parent
16be1a0bad
commit
fcb061b19a
@ -54,6 +54,7 @@ static gboolean opt_verbose_advisories;
|
||||
static gboolean opt_json;
|
||||
static gboolean opt_only_booted;
|
||||
static const char *opt_jsonpath;
|
||||
static gboolean opt_pending_exit_77;
|
||||
|
||||
static GOptionEntry option_entries[] = {
|
||||
{ "pretty", 'p', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_pretty, "This option is deprecated and no longer has any effect", NULL },
|
||||
@ -62,6 +63,7 @@ static GOptionEntry option_entries[] = {
|
||||
{ "json", 0, 0, G_OPTION_ARG_NONE, &opt_json, "Output JSON", NULL },
|
||||
{ "jsonpath", 'J', 0, G_OPTION_ARG_STRING, &opt_jsonpath, "Filter JSONPath expression", "EXPRESSION" },
|
||||
{ "booted", 'b', 0, G_OPTION_ARG_NONE, &opt_only_booted, "Only print the booted deployment", NULL },
|
||||
{ "pending-exit-77", 'b', 0, G_OPTION_ARG_NONE, &opt_pending_exit_77, "If pending deployment available, exit 77", NULL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@ -1026,5 +1028,18 @@ rpmostree_builtin_status (int argc,
|
||||
}
|
||||
}
|
||||
|
||||
if (opt_pending_exit_77)
|
||||
{
|
||||
if (g_variant_n_children (deployments) > 1)
|
||||
{
|
||||
g_autoptr(GVariant) pending = g_variant_get_child_value (deployments, 0);
|
||||
g_auto(GVariantDict) dict;
|
||||
g_variant_dict_init (&dict, pending);
|
||||
gboolean is_booted;
|
||||
if (g_variant_dict_lookup (&dict, "booted", "b", &is_booted) && !is_booted)
|
||||
invocation->exit_code = RPM_OSTREE_EXIT_PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ G_BEGIN_DECLS
|
||||
* Use alongside EXIT_SUCCESS and EXIT_FAILURE. */
|
||||
#define RPM_OSTREE_EXIT_UNCHANGED (77)
|
||||
|
||||
/* Exit code for when a pending deployment can be rebooted into. */
|
||||
#define RPM_OSTREE_EXIT_PENDING (77)
|
||||
|
||||
typedef enum {
|
||||
RPM_OSTREE_BUILTIN_FLAG_NONE = 0,
|
||||
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD = 1 << 0,
|
||||
|
@ -90,13 +90,25 @@ vm_rpmostree db diff --format=diff \
|
||||
assert_file_has_content_literal 'db-diff.txt' "+foo-1.0-1.x86_64"
|
||||
echo "ok pkg-add foo"
|
||||
|
||||
# Test that we don't do progress bars if on a tty (with the client)
|
||||
vm_rpmostree uninstall foo-1.0
|
||||
|
||||
# Test `rpm-ostree status --pending-exit-77`
|
||||
rc=0
|
||||
vm_rpmostree status --pending-exit-77 || rc=$?
|
||||
assert_streq $rc 77
|
||||
|
||||
# Test that we don't do progress bars if on a tty (with the client)
|
||||
vm_rpmostree install foo-1.0 > foo-install.txt
|
||||
assert_file_has_content_literal foo-install.txt 'Checking out packages (1/1) 100%'
|
||||
echo "ok install not on a tty"
|
||||
|
||||
vm_reboot
|
||||
|
||||
# Test `rpm-ostree status --pending-exit-77`, with no actual pending deployment
|
||||
rc=0
|
||||
vm_rpmostree status --pending-exit-77 || rc=$?
|
||||
assert_streq $rc 0
|
||||
|
||||
vm_assert_status_jq \
|
||||
'.deployments[0]["base-checksum"]' \
|
||||
'.deployments[0]["pending-base-checksum"]|not' \
|
||||
|
Loading…
Reference in New Issue
Block a user