Skip to content

Commit

Permalink
Move flags into command struct, pass down through builtins
Browse files Browse the repository at this point in the history
This is prep work for #682

Closes: #683
Approved by: jlebon
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Mar 16, 2017
1 parent 62a93c7 commit 12c34bb
Show file tree
Hide file tree
Showing 26 changed files with 169 additions and 90 deletions.
66 changes: 42 additions & 24 deletions src/app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,31 @@

static RpmOstreeCommand supported_commands[] = {
#ifdef HAVE_COMPOSE_TOOLING
{ "compose", rpmostree_builtin_compose },
{ "compose", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_compose },
#endif
{ "cleanup", rpmostree_builtin_cleanup },
{ "db", rpmostree_builtin_db },
{ "deploy", rpmostree_builtin_deploy },
{ "rebase", rpmostree_builtin_rebase },
{ "rollback", rpmostree_builtin_rollback },
{ "status", rpmostree_builtin_status },
{ "upgrade", rpmostree_builtin_upgrade },
{ "reload", rpmostree_builtin_reload },
{ "initramfs", rpmostree_builtin_initramfs },
{ "install", rpmostree_builtin_pkg_add },
{ "uninstall", rpmostree_builtin_pkg_remove },
{ "cleanup", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_cleanup },
{ "db", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_builtin_db },
{ "deploy", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_deploy },
{ "rebase", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_rebase },
{ "rollback", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_rollback },
{ "status", 0,
rpmostree_builtin_status },
{ "upgrade", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_upgrade },
{ "reload", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_reload },
{ "initramfs", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_initramfs },
{ "install", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_pkg_add },
{ "uninstall", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_pkg_remove },
{ NULL }
};

Expand All @@ -56,19 +68,24 @@ static RpmOstreeCommand preview_commands[] = {
};

static RpmOstreeCommand legacy_alias_commands[] = {
{ "pkg-add", rpmostree_builtin_pkg_add },
{ "pkg-remove", rpmostree_builtin_pkg_remove },
{ "pkg-add", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_pkg_add },
{ "pkg-remove", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_pkg_remove },
{ NULL }
};

static RpmOstreeCommand experimental_commands[] = {
{ "internals", rpmostree_builtin_internals },
{ "container", rpmostree_builtin_container },
{ "internals", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_builtin_internals },
{ "container", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_builtin_container },
{ NULL }
};

static RpmOstreeCommand hidden_commands[] = {
{ "start-daemon", rpmostree_builtin_start_daemon },
{ "start-daemon", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_builtin_start_daemon },
{ NULL }
};

Expand Down Expand Up @@ -123,15 +140,15 @@ rpmostree_option_context_parse (GOptionContext *context,
const GOptionEntry *main_entries,
int *argc,
char ***argv,
RpmOstreeBuiltinFlags flags,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable,
RPMOSTreeSysroot **out_sysroot_proxy,
GError **error)
{
gboolean use_daemon;
gboolean ret = FALSE;

use_daemon = ((flags & RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD) == 0);
/* with --version there's no command, don't require a daemon for it */
const RpmOstreeBuiltinFlags flags = invocation ? invocation->command->flags : RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD;
gboolean use_daemon = ((flags & RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD) == 0);

if (main_entries != NULL)
g_option_context_add_main_entries (context, main_entries, NULL);
Expand Down Expand Up @@ -320,8 +337,7 @@ main (int argc,

/* This will not return for some options (e.g. --version). */
(void) rpmostree_option_context_parse (context, NULL, &argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
NULL, NULL, NULL);
NULL, NULL, NULL, NULL);
if (command_name == NULL)
{
local_error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
Expand All @@ -343,7 +359,9 @@ main (int argc,
prgname = g_strdup_printf ("%s %s", g_get_prgname (), command_name);
g_set_prgname (prgname);

exit_status = command->fn (argc, argv, cancellable, &local_error);
{ RpmOstreeCommandInvocation invocation = { .command = command };
exit_status = command->fn (argc, argv, &invocation, cancellable, &local_error);
}

out:
if (local_error != NULL)
Expand Down
9 changes: 5 additions & 4 deletions src/app/rpmostree-builtin-cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ static GOptionEntry option_entries[] = {

int
rpmostree_builtin_cleanup (int argc,
char **argv,
GCancellable *cancellable,
GError **error)
char **argv,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable,
GError **error)
{
int exit_status = EXIT_FAILURE;
g_autoptr(GOptionContext) context = g_option_context_new ("- Clear cached/pending data");
Expand All @@ -61,7 +62,7 @@ rpmostree_builtin_cleanup (int argc,
if (!rpmostree_option_context_parse (context,
option_entries,
&argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
invocation,
cancellable,
&sysroot_proxy,
error))
Expand Down
15 changes: 10 additions & 5 deletions src/app/rpmostree-builtin-compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
#include <glib/gi18n.h>

static RpmOstreeCommand compose_subcommands[] = {
{ "tree", rpmostree_compose_builtin_tree },
{ NULL, NULL }
{ "tree", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
rpmostree_compose_builtin_tree },
{ NULL, 0, NULL }
};

static GOptionContext *
Expand Down Expand Up @@ -58,7 +59,9 @@ compose_option_context_new_with_commands (void)
}

int
rpmostree_builtin_compose (int argc, char **argv, GCancellable *cancellable, GError **error)
rpmostree_builtin_compose (int argc, char **argv,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable, GError **error)
{
RpmOstreeCommand *subcommand;
const char *subcommand_name = NULL;
Expand All @@ -84,7 +87,7 @@ rpmostree_builtin_compose (int argc, char **argv, GCancellable *cancellable, GEr
/* This will not return for some options (e.g. --version). */
(void) rpmostree_option_context_parse (context, NULL,
&argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
invocation,
cancellable,
NULL,
NULL);
Expand All @@ -109,7 +112,9 @@ rpmostree_builtin_compose (int argc, char **argv, GCancellable *cancellable, GEr
prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
g_set_prgname (prgname);

exit_status = subcommand->fn (argc, argv, cancellable, error);
{ RpmOstreeCommandInvocation sub_invocation = { .command = subcommand };
exit_status = subcommand->fn (argc, argv, &sub_invocation, cancellable, error);
}

out:
return exit_status;
Expand Down
19 changes: 12 additions & 7 deletions src/app/rpmostree-builtin-container.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
#include "rpmostree-rpm-util.h"

static RpmOstreeCommand container_subcommands[] = {
{ "init", rpmostree_container_builtin_init },
{ "assemble", rpmostree_container_builtin_assemble },
{ "init", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_container_builtin_init },
{ "assemble", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_container_builtin_assemble },
/* { "start", rpmostree_container_builtin_start }, */
{ "upgrade", rpmostree_container_builtin_upgrade },
{ NULL, NULL }
{ "upgrade", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_container_builtin_upgrade },
{ NULL, 0, NULL }
};

static GOptionContext *
Expand Down Expand Up @@ -56,7 +59,7 @@ container_option_context_new_with_commands (void)
}

int
rpmostree_builtin_container (int argc, char **argv, GCancellable *cancellable, GError **error)
rpmostree_builtin_container (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{
RpmOstreeCommand *subcommand;
const char *subcommand_name = NULL;
Expand All @@ -82,7 +85,7 @@ rpmostree_builtin_container (int argc, char **argv, GCancellable *cancellable, G
/* This will not return for some options (e.g. --version). */
(void) rpmostree_option_context_parse (context, NULL,
&argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
invocation,
cancellable,
NULL,
NULL);
Expand All @@ -107,7 +110,9 @@ rpmostree_builtin_container (int argc, char **argv, GCancellable *cancellable, G
prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
g_set_prgname (prgname);

exit_status = subcommand->fn (argc, argv, cancellable, error);
{ RpmOstreeCommandInvocation sub_invocation = { .command = subcommand };
exit_status = subcommand->fn (argc, argv, &sub_invocation, cancellable, error);
}

out:
return exit_status;
Expand Down
24 changes: 16 additions & 8 deletions src/app/rpmostree-builtin-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
#include "rpmostree-rpm-util.h"

static RpmOstreeCommand rpm_subcommands[] = {
{ "diff", rpmostree_db_builtin_diff },
{ "list", rpmostree_db_builtin_list },
{ "version", rpmostree_db_builtin_version },
{ NULL, NULL }
{ "diff", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_db_builtin_diff },
{ "list", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_db_builtin_list },
{ "version", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_db_builtin_version },
{ NULL, 0, NULL }
};

static char *opt_repo;
Expand Down Expand Up @@ -65,6 +68,7 @@ gboolean
rpmostree_db_option_context_parse (GOptionContext *context,
const GOptionEntry *main_entries,
int *argc, char ***argv,
RpmOstreeCommandInvocation *invocation,
OstreeRepo **out_repo,
GCancellable *cancellable, GError **error)
{
Expand All @@ -79,7 +83,7 @@ rpmostree_db_option_context_parse (GOptionContext *context,
if (!rpmostree_option_context_parse (context,
main_entries,
argc, argv,
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
invocation,
cancellable,
NULL,
error))
Expand Down Expand Up @@ -120,7 +124,9 @@ rpmostree_db_option_context_parse (GOptionContext *context,
}

int
rpmostree_builtin_db (int argc, char **argv, GCancellable *cancellable, GError **error)
rpmostree_builtin_db (int argc, char **argv,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable, GError **error)
{
RpmOstreeCommand *subcommand;
const char *subcommand_name = NULL;
Expand All @@ -146,7 +152,7 @@ rpmostree_builtin_db (int argc, char **argv, GCancellable *cancellable, GError *
/* This will not return for some options (e.g. --version). */
(void) rpmostree_option_context_parse (context, NULL,
&argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
invocation,
cancellable,
NULL,
NULL);
Expand All @@ -171,7 +177,9 @@ rpmostree_builtin_db (int argc, char **argv, GCancellable *cancellable, GError *
prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
g_set_prgname (prgname);

exit_status = subcommand->fn (argc, argv, cancellable, error);
{ RpmOstreeCommandInvocation sub_invocation = { .command = subcommand };
exit_status = subcommand->fn (argc, argv, &sub_invocation, cancellable, error);
}

out:
return exit_status;
Expand Down
3 changes: 2 additions & 1 deletion src/app/rpmostree-builtin-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ default_deployment_changed_cb (GObject *object,
int
rpmostree_builtin_deploy (int argc,
char **argv,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable,
GError **error)
{
Expand All @@ -81,7 +82,7 @@ rpmostree_builtin_deploy (int argc,
if (!rpmostree_option_context_parse (context,
option_entries,
&argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
invocation,
cancellable,
&sysroot_proxy,
error))
Expand Down
3 changes: 2 additions & 1 deletion src/app/rpmostree-builtin-initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ get_args_variant (void)
int
rpmostree_builtin_initramfs (int argc,
char **argv,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable,
GError **error)
{
Expand All @@ -68,7 +69,7 @@ rpmostree_builtin_initramfs (int argc,
if (!rpmostree_option_context_parse (context,
option_entries,
&argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT,
invocation,
cancellable,
&sysroot_proxy,
error))
Expand Down
15 changes: 10 additions & 5 deletions src/app/rpmostree-builtin-internals.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
#include "rpmostree-rpm-util.h"

static RpmOstreeCommand internals_subcommands[] = {
{ "unpack", rpmostree_internals_builtin_unpack },
{ NULL, NULL }
{ "unpack", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
rpmostree_internals_builtin_unpack },
{ NULL, 0, NULL }
};

/*
Expand Down Expand Up @@ -59,7 +60,9 @@ internals_option_context_new_with_commands (void)
}

int
rpmostree_builtin_internals (int argc, char **argv, GCancellable *cancellable, GError **error)
rpmostree_builtin_internals (int argc, char **argv,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable, GError **error)
{
RpmOstreeCommand *subcommand;
const char *subcommand_name = NULL;
Expand All @@ -84,7 +87,7 @@ rpmostree_builtin_internals (int argc, char **argv, GCancellable *cancellable, G
/* This will not return for some options (e.g. --version). */
(void) rpmostree_option_context_parse (context, NULL,
&argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
invocation,
cancellable,
NULL,
NULL);
Expand All @@ -109,7 +112,9 @@ rpmostree_builtin_internals (int argc, char **argv, GCancellable *cancellable, G
prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
g_set_prgname (prgname);

exit_status = subcommand->fn (argc, argv, cancellable, error);
{ RpmOstreeCommandInvocation sub_invocation = { .command = subcommand };
exit_status = subcommand->fn (argc, argv, &sub_invocation, cancellable, error);
}

out:
return exit_status;
Expand Down
3 changes: 2 additions & 1 deletion src/app/rpmostree-builtin-rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ get_args_variant (const char *revision)
int
rpmostree_builtin_rebase (int argc,
char **argv,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable,
GError **error)
{
Expand All @@ -77,7 +78,7 @@ rpmostree_builtin_rebase (int argc,
if (!rpmostree_option_context_parse (context,
option_entries,
&argc, &argv,
RPM_OSTREE_BUILTIN_FLAG_NONE,
invocation,
cancellable,
&sysroot_proxy,
error))
Expand Down
Loading

0 comments on commit 12c34bb

Please sign in to comment.