From bf295f1e342f3ed552d3c4efe1882884c03beed0 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 15 Mar 2017 14:52:43 -0400 Subject: [PATCH 1/6] Move flags into command struct, pass down through builtins This is prep work for https://github.com/projectatomic/rpm-ostree/issues/682 --- src/app/main.c | 66 +++++++++++++------- src/app/rpmostree-builtin-cleanup.c | 9 +-- src/app/rpmostree-builtin-compose.c | 15 +++-- src/app/rpmostree-builtin-container.c | 19 +++--- src/app/rpmostree-builtin-db.c | 24 ++++--- src/app/rpmostree-builtin-deploy.c | 3 +- src/app/rpmostree-builtin-initramfs.c | 3 +- src/app/rpmostree-builtin-internals.c | 15 +++-- src/app/rpmostree-builtin-rebase.c | 3 +- src/app/rpmostree-builtin-reload.c | 3 +- src/app/rpmostree-builtin-rollback.c | 3 +- src/app/rpmostree-builtin-start-daemon.c | 1 + src/app/rpmostree-builtin-status.c | 3 +- src/app/rpmostree-builtin-upgrade.c | 3 +- src/app/rpmostree-builtins.h | 24 +++++-- src/app/rpmostree-compose-builtin-tree.c | 3 +- src/app/rpmostree-compose-builtins.h | 2 +- src/app/rpmostree-container-builtins.c | 12 ++-- src/app/rpmostree-container-builtins.h | 8 +-- src/app/rpmostree-db-builtin-diff.c | 6 +- src/app/rpmostree-db-builtin-list.c | 8 ++- src/app/rpmostree-db-builtin-version.c | 6 +- src/app/rpmostree-db-builtins.h | 7 ++- src/app/rpmostree-internals-builtin-unpack.c | 3 +- src/app/rpmostree-internals-builtins.h | 4 +- src/app/rpmostree-pkg-builtins.c | 6 +- 26 files changed, 169 insertions(+), 90 deletions(-) diff --git a/src/app/main.c b/src/app/main.c index 6be70cf780..c6f3e7975e 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -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 } }; @@ -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 } }; @@ -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); @@ -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, @@ -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) diff --git a/src/app/rpmostree-builtin-cleanup.c b/src/app/rpmostree-builtin-cleanup.c index da7185b469..8124a689f2 100644 --- a/src/app/rpmostree-builtin-cleanup.c +++ b/src/app/rpmostree-builtin-cleanup.c @@ -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"); @@ -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)) diff --git a/src/app/rpmostree-builtin-compose.c b/src/app/rpmostree-builtin-compose.c index ca0f463afe..34838fe827 100644 --- a/src/app/rpmostree-builtin-compose.c +++ b/src/app/rpmostree-builtin-compose.c @@ -29,8 +29,9 @@ #include 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 * @@ -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; @@ -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); @@ -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; diff --git a/src/app/rpmostree-builtin-container.c b/src/app/rpmostree-builtin-container.c index 42938bf542..caa2d80401 100644 --- a/src/app/rpmostree-builtin-container.c +++ b/src/app/rpmostree-builtin-container.c @@ -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 * @@ -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; @@ -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); @@ -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; diff --git a/src/app/rpmostree-builtin-db.c b/src/app/rpmostree-builtin-db.c index 9e084abd73..c6b088894a 100644 --- a/src/app/rpmostree-builtin-db.c +++ b/src/app/rpmostree-builtin-db.c @@ -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; @@ -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) { @@ -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)) @@ -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; @@ -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); @@ -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; diff --git a/src/app/rpmostree-builtin-deploy.c b/src/app/rpmostree-builtin-deploy.c index ea86ded354..cdd3db32f1 100644 --- a/src/app/rpmostree-builtin-deploy.c +++ b/src/app/rpmostree-builtin-deploy.c @@ -64,6 +64,7 @@ default_deployment_changed_cb (GObject *object, int rpmostree_builtin_deploy (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -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)) diff --git a/src/app/rpmostree-builtin-initramfs.c b/src/app/rpmostree-builtin-initramfs.c index 835419c0bb..6640ff0142 100644 --- a/src/app/rpmostree-builtin-initramfs.c +++ b/src/app/rpmostree-builtin-initramfs.c @@ -56,6 +56,7 @@ get_args_variant (void) int rpmostree_builtin_initramfs (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -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)) diff --git a/src/app/rpmostree-builtin-internals.c b/src/app/rpmostree-builtin-internals.c index 6797e6fec9..6e626d8f39 100644 --- a/src/app/rpmostree-builtin-internals.c +++ b/src/app/rpmostree-builtin-internals.c @@ -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 } }; /* @@ -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; @@ -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); @@ -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; diff --git a/src/app/rpmostree-builtin-rebase.c b/src/app/rpmostree-builtin-rebase.c index 72f97811c5..7507063402 100644 --- a/src/app/rpmostree-builtin-rebase.c +++ b/src/app/rpmostree-builtin-rebase.c @@ -59,6 +59,7 @@ get_args_variant (const char *revision) int rpmostree_builtin_rebase (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -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)) diff --git a/src/app/rpmostree-builtin-reload.c b/src/app/rpmostree-builtin-reload.c index 83441ebb46..a95f9556ff 100644 --- a/src/app/rpmostree-builtin-reload.c +++ b/src/app/rpmostree-builtin-reload.c @@ -36,6 +36,7 @@ static GOptionEntry option_entries[] = { int rpmostree_builtin_reload (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -46,7 +47,7 @@ rpmostree_builtin_reload (int argc, if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + invocation, cancellable, &sysroot_proxy, error)) diff --git a/src/app/rpmostree-builtin-rollback.c b/src/app/rpmostree-builtin-rollback.c index 1048e7b7a9..bb1d21663f 100644 --- a/src/app/rpmostree-builtin-rollback.c +++ b/src/app/rpmostree-builtin-rollback.c @@ -50,6 +50,7 @@ get_args_variant (void) int rpmostree_builtin_rollback (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -63,7 +64,7 @@ rpmostree_builtin_rollback (int argc, if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + invocation, cancellable, &sysroot_proxy, error)) diff --git a/src/app/rpmostree-builtin-start-daemon.c b/src/app/rpmostree-builtin-start-daemon.c index 9bbcbd181e..8ddba4b57b 100644 --- a/src/app/rpmostree-builtin-start-daemon.c +++ b/src/app/rpmostree-builtin-start-daemon.c @@ -304,6 +304,7 @@ connect_to_peer (int fd, GError **error) int rpmostree_builtin_start_daemon (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { diff --git a/src/app/rpmostree-builtin-status.c b/src/app/rpmostree-builtin-status.c index f8684dd0bf..ca6b26a234 100644 --- a/src/app/rpmostree-builtin-status.c +++ b/src/app/rpmostree-builtin-status.c @@ -369,6 +369,7 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy, int rpmostree_builtin_status (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -381,7 +382,7 @@ rpmostree_builtin_status (int argc, if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_NONE, + invocation, cancellable, &sysroot_proxy, error)) diff --git a/src/app/rpmostree-builtin-upgrade.c b/src/app/rpmostree-builtin-upgrade.c index 3d95f95f3c..b2d3be6f22 100644 --- a/src/app/rpmostree-builtin-upgrade.c +++ b/src/app/rpmostree-builtin-upgrade.c @@ -65,6 +65,7 @@ get_args_variant (void) int rpmostree_builtin_upgrade (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -79,7 +80,7 @@ rpmostree_builtin_upgrade (int argc, if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + invocation, cancellable, &sysroot_proxy, error)) diff --git a/src/app/rpmostree-builtins.h b/src/app/rpmostree-builtins.h index 123b267ec8..2756ae792e 100644 --- a/src/app/rpmostree-builtins.h +++ b/src/app/rpmostree-builtins.h @@ -35,12 +35,26 @@ typedef enum { RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT = 1 << 1, } RpmOstreeBuiltinFlags; -typedef struct { +typedef struct RpmOstreeCommand RpmOstreeCommand; +typedef struct RpmOstreeCommandInvocation RpmOstreeCommandInvocation; + +struct RpmOstreeCommand { const char *name; - int (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error); -} RpmOstreeCommand; + RpmOstreeBuiltinFlags flags; + int (*fn) (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +}; + +/* Currently, this has just the command (which is mostly there for the + * name/flags), but in the future if we want to add something new we won't need + * to touch every prototype. + */ +struct RpmOstreeCommandInvocation { + RpmOstreeCommand *command; +}; -#define BUILTINPROTO(name) gboolean rpmostree_builtin_ ## name (int argc, char **argv, GCancellable *cancellable, GError **error) +#define BUILTINPROTO(name) gboolean rpmostree_builtin_ ## name (int argc, char **argv, \ + RpmOstreeCommandInvocation *invocation, \ + GCancellable *cancellable, GError **error) BUILTINPROTO(compose); BUILTINPROTO(upgrade); @@ -67,7 +81,7 @@ gboolean 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); diff --git a/src/app/rpmostree-compose-builtin-tree.c b/src/app/rpmostree-compose-builtin-tree.c index 31accdaf20..31bb120bfe 100644 --- a/src/app/rpmostree-compose-builtin-tree.c +++ b/src/app/rpmostree-compose-builtin-tree.c @@ -595,6 +595,7 @@ process_touch_if_changed (GError **error) int rpmostree_compose_builtin_tree (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -630,7 +631,7 @@ rpmostree_compose_builtin_tree (int argc, if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + invocation, cancellable, NULL, error)) diff --git a/src/app/rpmostree-compose-builtins.h b/src/app/rpmostree-compose-builtins.h index c7b8646e2c..171227dd75 100644 --- a/src/app/rpmostree-compose-builtins.h +++ b/src/app/rpmostree-compose-builtins.h @@ -26,7 +26,7 @@ G_BEGIN_DECLS -gboolean rpmostree_compose_builtin_tree (int argc, char **argv, GCancellable *cancellable, GError **error); +gboolean rpmostree_compose_builtin_tree (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/app/rpmostree-container-builtins.c b/src/app/rpmostree-container-builtins.c index a5fceba06a..1fe26098d5 100644 --- a/src/app/rpmostree-container-builtins.c +++ b/src/app/rpmostree-container-builtins.c @@ -141,6 +141,7 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ROContainerContext, roc_context_deinit) int rpmostree_container_builtin_init (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -154,7 +155,7 @@ rpmostree_container_builtin_init (int argc, if (!rpmostree_option_context_parse (context, init_option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, + invocation, cancellable, NULL, error)) @@ -227,6 +228,7 @@ symlink_at_replace (const char *oldpath, int rpmostree_container_builtin_assemble (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -245,7 +247,7 @@ rpmostree_container_builtin_assemble (int argc, if (!rpmostree_option_context_parse (context, assemble_option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, + invocation, cancellable, NULL, error)) @@ -407,7 +409,9 @@ parse_app_version (const char *name, } gboolean -rpmostree_container_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GError **error) +rpmostree_container_builtin_upgrade (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { int exit_status = EXIT_FAILURE; g_autoptr(GOptionContext) context = g_option_context_new ("NAME"); @@ -429,7 +433,7 @@ rpmostree_container_builtin_upgrade (int argc, char **argv, GCancellable *cancel if (!rpmostree_option_context_parse (context, assemble_option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, + invocation, cancellable, NULL, error)) diff --git a/src/app/rpmostree-container-builtins.h b/src/app/rpmostree-container-builtins.h index b6cc7dd4d4..a7c0f2f1c9 100644 --- a/src/app/rpmostree-container-builtins.h +++ b/src/app/rpmostree-container-builtins.h @@ -26,10 +26,10 @@ G_BEGIN_DECLS -gboolean rpmostree_container_builtin_init (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean rpmostree_container_builtin_assemble (int argc, char **argv, GCancellable *cancellable, GError **error); -/* gboolean rpmostree_container_builtin_start (int argc, char **argv, GCancellable *cancellable, GError **error); */ -gboolean rpmostree_container_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GError **error); +gboolean rpmostree_container_builtin_init (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +gboolean rpmostree_container_builtin_assemble (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +/* gboolean rpmostree_container_builtin_start (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); */ +gboolean rpmostree_container_builtin_upgrade (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/app/rpmostree-db-builtin-diff.c b/src/app/rpmostree-db-builtin-diff.c index e607bb245a..9d25278f3e 100644 --- a/src/app/rpmostree-db-builtin-diff.c +++ b/src/app/rpmostree-db-builtin-diff.c @@ -34,7 +34,9 @@ static GOptionEntry option_entries[] = { }; int -rpmostree_db_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError **error) +rpmostree_db_builtin_diff (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { int exit_status = EXIT_FAILURE; g_autoptr(GOptionContext) context = NULL; @@ -44,7 +46,7 @@ rpmostree_db_builtin_diff (int argc, char **argv, GCancellable *cancellable, GEr context = g_option_context_new ("COMMIT COMMIT - Show package changes between two commits"); - if (!rpmostree_db_option_context_parse (context, option_entries, &argc, &argv, &repo, + if (!rpmostree_db_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, cancellable, error)) goto out; diff --git a/src/app/rpmostree-db-builtin-list.c b/src/app/rpmostree-db-builtin-list.c index fc1262222b..f9129e3b61 100644 --- a/src/app/rpmostree-db-builtin-list.c +++ b/src/app/rpmostree-db-builtin-list.c @@ -85,7 +85,9 @@ _builtin_db_list (OstreeRepo *repo, } int -rpmostree_db_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error) +rpmostree_db_builtin_list (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { int exit_status = EXIT_FAILURE; g_autoptr(GOptionContext) context = NULL; @@ -96,8 +98,8 @@ rpmostree_db_builtin_list (int argc, char **argv, GCancellable *cancellable, GEr context = g_option_context_new ("[PREFIX-PKGNAME...] COMMIT... - List packages within commits"); - if (!rpmostree_db_option_context_parse (context, option_entries, &argc, &argv, &repo, - cancellable, error)) + if (!rpmostree_db_option_context_parse (context, option_entries, &argc, &argv, invocation, + &repo, cancellable, error)) goto out; /* Iterate over all arguments. When we see the first argument which diff --git a/src/app/rpmostree-db-builtin-version.c b/src/app/rpmostree-db-builtin-version.c index 03e5c2aa67..3c8067b769 100644 --- a/src/app/rpmostree-db-builtin-version.c +++ b/src/app/rpmostree-db-builtin-version.c @@ -90,7 +90,9 @@ _builtin_db_version (OstreeRepo *repo, GPtrArray *revs, } int -rpmostree_db_builtin_version (int argc, char **argv, GCancellable *cancellable, GError **error) +rpmostree_db_builtin_version (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { int exit_status = EXIT_FAILURE; g_autoptr(GOptionContext) context = NULL; @@ -100,7 +102,7 @@ rpmostree_db_builtin_version (int argc, char **argv, GCancellable *cancellable, context = g_option_context_new ("COMMIT... - Show rpmdb version of packages within the commits"); - if (!rpmostree_db_option_context_parse (context, db_version_entries, &argc, &argv, &repo, + if (!rpmostree_db_option_context_parse (context, db_version_entries, &argc, &argv, invocation, &repo, cancellable, error)) goto out; diff --git a/src/app/rpmostree-db-builtins.h b/src/app/rpmostree-db-builtins.h index 703c088655..68db029f5a 100644 --- a/src/app/rpmostree-db-builtins.h +++ b/src/app/rpmostree-db-builtins.h @@ -26,13 +26,14 @@ G_BEGIN_DECLS -gboolean rpmostree_db_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean rpmostree_db_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean rpmostree_db_builtin_version (int argc, char **argv, GCancellable *cancellable, GError **error); +gboolean rpmostree_db_builtin_diff (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +gboolean rpmostree_db_builtin_list (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +gboolean rpmostree_db_builtin_version (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); 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); diff --git a/src/app/rpmostree-internals-builtin-unpack.c b/src/app/rpmostree-internals-builtin-unpack.c index 0b034b03d6..25cd097767 100644 --- a/src/app/rpmostree-internals-builtin-unpack.c +++ b/src/app/rpmostree-internals-builtin-unpack.c @@ -53,6 +53,7 @@ static GOptionEntry option_entries[] = { int rpmostree_internals_builtin_unpack (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -68,7 +69,7 @@ rpmostree_internals_builtin_unpack (int argc, if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, + invocation, cancellable, NULL, error)) diff --git a/src/app/rpmostree-internals-builtins.h b/src/app/rpmostree-internals-builtins.h index 506f73123f..95f3280325 100644 --- a/src/app/rpmostree-internals-builtins.h +++ b/src/app/rpmostree-internals-builtins.h @@ -26,8 +26,8 @@ G_BEGIN_DECLS -gboolean rpmostree_internals_builtin_unpack (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean rpmostree_internals_builtin_start_daemon (int argc, char **argv, GCancellable *cancellable, GError **error); +gboolean rpmostree_internals_builtin_unpack (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +gboolean rpmostree_internals_builtin_start_daemon (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/app/rpmostree-pkg-builtins.c b/src/app/rpmostree-pkg-builtins.c index 330ddc2a9f..2c64009117 100644 --- a/src/app/rpmostree-pkg-builtins.c +++ b/src/app/rpmostree-pkg-builtins.c @@ -132,6 +132,7 @@ pkg_change (RPMOSTreeSysroot *sysroot_proxy, int rpmostree_builtin_pkg_add (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -145,7 +146,7 @@ rpmostree_builtin_pkg_add (int argc, if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + invocation, cancellable, &sysroot_proxy, error)) @@ -197,6 +198,7 @@ rpmostree_builtin_pkg_add (int argc, int rpmostree_builtin_pkg_remove (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -209,7 +211,7 @@ rpmostree_builtin_pkg_remove (int argc, if (!rpmostree_option_context_parse (context, option_entries, &argc, &argv, - RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + invocation, cancellable, &sysroot_proxy, error)) From 0f392b541f650acd0db0f4e139a9b3ffc3b752f9 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 15 Mar 2017 15:30:59 -0400 Subject: [PATCH 2/6] main: Remove unused "preview" commands --- src/app/main.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/app/main.c b/src/app/main.c index c6f3e7975e..b6c81d7829 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -63,10 +63,6 @@ static RpmOstreeCommand supported_commands[] = { { NULL } }; -static RpmOstreeCommand preview_commands[] = { - { NULL } -}; - static RpmOstreeCommand legacy_alias_commands[] = { { "pkg-add", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, rpmostree_builtin_pkg_add }, @@ -121,13 +117,6 @@ option_context_new_with_commands (void) command++; } - command = preview_commands; - while (command->name != NULL) - { - g_string_append_printf (summary, "\n %s (preview)", command->name); - command++; - } - g_option_context_set_summary (context, summary->str); g_string_free (summary, TRUE); @@ -321,9 +310,6 @@ main (int argc, if (!command) command = lookup_command_of_type (legacy_alias_commands, command_name, NULL); - if (!command) - command = lookup_command_of_type (preview_commands, command_name, "a preview"); - if (!command) command = lookup_command_of_type (experimental_commands, command_name, "an experimental"); From d9dcda20bd3e10ab0d30827cb5252eb8c0f02e9d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 15 Mar 2017 16:20:03 -0400 Subject: [PATCH 3/6] app: Make hidden/experimental flags for command parsing I think this ends up being cleaner - the properties of a command are now consistently represented as flags. Prep work for https://github.com/projectatomic/rpm-ostree/issues/682 --- src/app/main.c | 79 +++++++++++---------------- src/app/rpmostree-builtin-compose.c | 4 +- src/app/rpmostree-builtin-container.c | 5 +- src/app/rpmostree-builtin-db.c | 2 +- src/app/rpmostree-builtin-internals.c | 5 +- src/app/rpmostree-builtins.h | 5 +- 6 files changed, 44 insertions(+), 56 deletions(-) diff --git a/src/app/main.c b/src/app/main.c index b6c81d7829..bb24884f3f 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -33,7 +33,7 @@ #include "libglnx.h" -static RpmOstreeCommand supported_commands[] = { +static RpmOstreeCommand commands[] = { #ifdef HAVE_COMPOSE_TOOLING { "compose", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, rpmostree_builtin_compose }, @@ -60,27 +60,19 @@ static RpmOstreeCommand supported_commands[] = { rpmostree_builtin_pkg_add }, { "uninstall", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, rpmostree_builtin_pkg_remove }, - { NULL } -}; - -static RpmOstreeCommand legacy_alias_commands[] = { - { "pkg-add", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + /* Legacy aliases */ + { "pkg-add", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT | RPM_OSTREE_BUILTIN_FLAG_HIDDEN, rpmostree_builtin_pkg_add }, - { "pkg-remove", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + { "pkg-remove", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT | RPM_OSTREE_BUILTIN_FLAG_HIDDEN, rpmostree_builtin_pkg_remove }, - { NULL } -}; - -static RpmOstreeCommand experimental_commands[] = { - { "internals", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, + /* Experimental */ + { "internals", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL, rpmostree_builtin_internals }, - { "container", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, + { "container", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL, rpmostree_builtin_container }, - { NULL } -}; - -static RpmOstreeCommand hidden_commands[] = { - { "start-daemon", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + /* Hidden */ + { "start-daemon", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT | + RPM_OSTREE_BUILTIN_FLAG_HIDDEN, rpmostree_builtin_start_daemon }, { NULL } }; @@ -103,7 +95,7 @@ static GOptionEntry daemon_entries[] = { static GOptionContext * option_context_new_with_commands (void) { - RpmOstreeCommand *command = supported_commands; + RpmOstreeCommand *command = commands; GOptionContext *context; GString *summary; @@ -113,7 +105,10 @@ option_context_new_with_commands (void) while (command->name != NULL) { - g_string_append_printf (summary, "\n %s", command->name); + gboolean is_hidden = (command->flags & RPM_OSTREE_BUILTIN_FLAG_HIDDEN) > 0; + gboolean is_experimental = (command->flags & RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL) > 0; + if (!(is_hidden || is_experimental)) + g_string_append_printf (summary, "\n %s", command->name); command++; } @@ -219,27 +214,14 @@ rpmostree_print_gpg_verify_result (OstreeGpgVerifyResult *result) static RpmOstreeCommand * -lookup_command_of_type (RpmOstreeCommand *commands, - const char *name, - const char *type) +lookup_command (const char *name) { RpmOstreeCommand *command = commands; - const int is_tty = isatty (1); - const char *bold_prefix; - const char *bold_suffix; - - bold_prefix = is_tty ? "\x1b[1m" : ""; - bold_suffix = is_tty ? "\x1b[0m" : ""; while (command->name) { if (g_strcmp0 (name, command->name) == 0) - { - if (type) - g_printerr ("%snotice%s: %s is %s command and subject to change.\n", - bold_prefix, bold_suffix, name, type); - return command; - } + return command; command++; } return NULL; @@ -247,12 +229,25 @@ lookup_command_of_type (RpmOstreeCommand *commands, const char * rpmostree_subcommand_parse (int *inout_argc, - char **inout_argv) + char **inout_argv, + RpmOstreeCommandInvocation *invocation) { const int argc = *inout_argc; const char *command_name = NULL; int in, out; + if (invocation && (invocation->command->flags & RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL) > 0) + { + const int is_tty = isatty (1); + const char *bold_prefix = is_tty ? "\x1b[1m" : ""; + const char *bold_suffix = is_tty ? "\x1b[0m" : ""; + + g_assert (invocation); + + g_printerr ("%snotice%s: %s is an experimental command and subject to change.\n", + bold_prefix, bold_suffix, invocation->command->name); + } + for (in = 1, out = 1; in < argc; in++, out++) { /* The non-option is the command, take it out of the arguments */ @@ -300,21 +295,13 @@ main (int argc, * necessary, in order to pass relevant options through * to the commands, but also have them take effect globally. */ - command_name = rpmostree_subcommand_parse (&argc, argv); + command_name = rpmostree_subcommand_parse (&argc, argv, NULL); /* Keep the "rpm" command working for backward-compatibility. */ if (g_strcmp0 (command_name, "rpm") == 0) command_name = "db"; - command = lookup_command_of_type (supported_commands, command_name, NULL); - if (!command) - command = lookup_command_of_type (legacy_alias_commands, command_name, NULL); - - if (!command) - command = lookup_command_of_type (experimental_commands, command_name, "an experimental"); - - if (!command) - command = lookup_command_of_type (hidden_commands, command_name, NULL); + command = lookup_command (command_name); if (!command) { diff --git a/src/app/rpmostree-builtin-compose.c b/src/app/rpmostree-builtin-compose.c index 34838fe827..6557a3b86a 100644 --- a/src/app/rpmostree-builtin-compose.c +++ b/src/app/rpmostree-builtin-compose.c @@ -29,7 +29,7 @@ #include static RpmOstreeCommand compose_subcommands[] = { - { "tree", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, + { "tree", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT, rpmostree_compose_builtin_tree }, { NULL, 0, NULL } }; @@ -68,7 +68,7 @@ rpmostree_builtin_compose (int argc, char **argv, g_autofree char *prgname = NULL; int exit_status = EXIT_SUCCESS; - subcommand_name = rpmostree_subcommand_parse (&argc, argv); + subcommand_name = rpmostree_subcommand_parse (&argc, argv, invocation); subcommand = compose_subcommands; while (subcommand->name) diff --git a/src/app/rpmostree-builtin-container.c b/src/app/rpmostree-builtin-container.c index caa2d80401..47784ebc6c 100644 --- a/src/app/rpmostree-builtin-container.c +++ b/src/app/rpmostree-builtin-container.c @@ -66,8 +66,7 @@ rpmostree_builtin_container (int argc, char **argv, RpmOstreeCommandInvocation * g_autofree char *prgname = NULL; int exit_status = EXIT_SUCCESS; - subcommand_name = rpmostree_subcommand_parse (&argc, argv); - + subcommand_name = rpmostree_subcommand_parse (&argc, argv, invocation); subcommand = container_subcommands; while (subcommand->name) { @@ -82,13 +81,13 @@ rpmostree_builtin_container (int argc, char **argv, RpmOstreeCommandInvocation * container_option_context_new_with_commands (); g_autofree char *help = NULL; - /* This will not return for some options (e.g. --version). */ (void) rpmostree_option_context_parse (context, NULL, &argc, &argv, invocation, cancellable, NULL, NULL); + if (subcommand_name == NULL) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, diff --git a/src/app/rpmostree-builtin-db.c b/src/app/rpmostree-builtin-db.c index c6b088894a..4ed9e693ba 100644 --- a/src/app/rpmostree-builtin-db.c +++ b/src/app/rpmostree-builtin-db.c @@ -133,7 +133,7 @@ rpmostree_builtin_db (int argc, char **argv, g_autofree char *prgname = NULL; int exit_status = EXIT_SUCCESS; - subcommand_name = rpmostree_subcommand_parse (&argc, argv); + subcommand_name = rpmostree_subcommand_parse (&argc, argv, invocation); subcommand = rpm_subcommands; while (subcommand->name) diff --git a/src/app/rpmostree-builtin-internals.c b/src/app/rpmostree-builtin-internals.c index 6e626d8f39..88667f048c 100644 --- a/src/app/rpmostree-builtin-internals.c +++ b/src/app/rpmostree-builtin-internals.c @@ -69,8 +69,7 @@ rpmostree_builtin_internals (int argc, char **argv, g_autofree char *prgname = NULL; int exit_status = EXIT_SUCCESS; - subcommand_name = rpmostree_subcommand_parse (&argc, argv); - + subcommand_name = rpmostree_subcommand_parse (&argc, argv, invocation); subcommand = internals_subcommands; while (subcommand->name) { @@ -84,13 +83,13 @@ rpmostree_builtin_internals (int argc, char **argv, g_autoptr(GOptionContext) context = internals_option_context_new_with_commands (); g_autofree char *help = NULL; - /* This will not return for some options (e.g. --version). */ (void) rpmostree_option_context_parse (context, NULL, &argc, &argv, invocation, cancellable, NULL, NULL); + if (subcommand_name == NULL) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, diff --git a/src/app/rpmostree-builtins.h b/src/app/rpmostree-builtins.h index 2756ae792e..c81c288132 100644 --- a/src/app/rpmostree-builtins.h +++ b/src/app/rpmostree-builtins.h @@ -33,6 +33,8 @@ typedef enum { RPM_OSTREE_BUILTIN_FLAG_NONE = 0, RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD = 1 << 0, RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT = 1 << 1, + RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL = 1 << 2, + RPM_OSTREE_BUILTIN_FLAG_HIDDEN = 1 << 3, } RpmOstreeBuiltinFlags; typedef struct RpmOstreeCommand RpmOstreeCommand; @@ -75,7 +77,8 @@ BUILTINPROTO(start_daemon); #undef BUILTINPROTO const char *rpmostree_subcommand_parse (int *inout_argc, - char **inout_argv); + char **inout_argv, + RpmOstreeCommandInvocation *invocation); gboolean rpmostree_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, From 2f8b2e5abafd53038d10b0a73e42f38d4fca67d2 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 15 Mar 2017 21:05:14 -0400 Subject: [PATCH 4/6] =?UTF-8?q?app:=20Rename=20internals=20=E2=86=92=20ex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The goal is to consolidate our "experimental" functionality under one subcommand. This makes it easier to determine when things "graduate" to permanent-stability status under the main command line. Closes: https://github.com/projectatomic/rpm-ostree/issues/682 --- Makefile-rpm-ostree.am | 4 ++-- src/app/main.c | 4 ++-- ...tin-internals.c => rpmostree-builtin-ex.c} | 24 +++++++++---------- src/app/rpmostree-builtin-start-daemon.c | 2 +- src/app/rpmostree-builtins.h | 1 + ...unpack.c => rpmostree-ex-builtin-unpack.c} | 12 +++++----- ...als-builtins.h => rpmostree-ex-builtins.h} | 3 +-- 7 files changed, 25 insertions(+), 25 deletions(-) rename src/app/{rpmostree-builtin-internals.c => rpmostree-builtin-ex.c} (81%) rename src/app/{rpmostree-internals-builtin-unpack.c => rpmostree-ex-builtin-unpack.c} (90%) rename src/app/{rpmostree-internals-builtins.h => rpmostree-ex-builtins.h} (75%) diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am index 5a21a634ed..10228d16f1 100644 --- a/Makefile-rpm-ostree.am +++ b/Makefile-rpm-ostree.am @@ -32,7 +32,7 @@ rpm_ostree_SOURCES = src/app/main.c \ src/app/rpmostree-builtin-initramfs.c \ src/app/rpmostree-pkg-builtins.c \ src/app/rpmostree-builtin-status.c \ - src/app/rpmostree-builtin-internals.c \ + src/app/rpmostree-builtin-ex.c \ src/app/rpmostree-builtin-container.c \ src/app/rpmostree-builtin-db.c \ src/app/rpmostree-builtin-start-daemon.c \ @@ -43,7 +43,7 @@ rpm_ostree_SOURCES = src/app/main.c \ src/app/rpmostree-dbus-helpers.h \ src/app/rpmostree-container-builtins.h \ src/app/rpmostree-container-builtins.c \ - src/app/rpmostree-internals-builtin-unpack.c \ + src/app/rpmostree-ex-builtin-unpack.c \ src/app/rpmostree-libbuiltin.c \ src/app/rpmostree-libbuiltin.h \ $(NULL) diff --git a/src/app/main.c b/src/app/main.c index bb24884f3f..a8248ac99a 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -66,8 +66,8 @@ static RpmOstreeCommand commands[] = { { "pkg-remove", RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT | RPM_OSTREE_BUILTIN_FLAG_HIDDEN, rpmostree_builtin_pkg_remove }, /* Experimental */ - { "internals", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL, - rpmostree_builtin_internals }, + { "ex", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL, + rpmostree_builtin_ex }, { "container", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL, rpmostree_builtin_container }, /* Hidden */ diff --git a/src/app/rpmostree-builtin-internals.c b/src/app/rpmostree-builtin-ex.c similarity index 81% rename from src/app/rpmostree-builtin-internals.c rename to src/app/rpmostree-builtin-ex.c index 88667f048c..fd50523eeb 100644 --- a/src/app/rpmostree-builtin-internals.c +++ b/src/app/rpmostree-builtin-ex.c @@ -20,12 +20,12 @@ #include "config.h" -#include "rpmostree-internals-builtins.h" +#include "rpmostree-ex-builtins.h" #include "rpmostree-rpm-util.h" -static RpmOstreeCommand internals_subcommands[] = { +static RpmOstreeCommand ex_subcommands[] = { { "unpack", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, - rpmostree_internals_builtin_unpack }, + rpmostree_ex_builtin_unpack }, { NULL, 0, NULL } }; @@ -36,15 +36,15 @@ static GOptionEntry global_entries[] = { */ static GOptionContext * -internals_option_context_new_with_commands (void) +ex_option_context_new_with_commands (void) { - RpmOstreeCommand *command = internals_subcommands; + RpmOstreeCommand *command = ex_subcommands; GOptionContext *context; GString *summary; context = g_option_context_new ("COMMAND"); - summary = g_string_new ("Builtin \"internals\" Commands:"); + summary = g_string_new ("Builtin \"ex\" Commands:"); while (command->name != NULL) { @@ -60,9 +60,9 @@ internals_option_context_new_with_commands (void) } int -rpmostree_builtin_internals (int argc, char **argv, - RpmOstreeCommandInvocation *invocation, - GCancellable *cancellable, GError **error) +rpmostree_builtin_ex (int argc, char **argv, + RpmOstreeCommandInvocation *invocation, + GCancellable *cancellable, GError **error) { RpmOstreeCommand *subcommand; const char *subcommand_name = NULL; @@ -70,7 +70,7 @@ rpmostree_builtin_internals (int argc, char **argv, int exit_status = EXIT_SUCCESS; subcommand_name = rpmostree_subcommand_parse (&argc, argv, invocation); - subcommand = internals_subcommands; + subcommand = ex_subcommands; while (subcommand->name) { if (g_strcmp0 (subcommand_name, subcommand->name) == 0) @@ -93,12 +93,12 @@ rpmostree_builtin_internals (int argc, char **argv, if (subcommand_name == NULL) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "No \"internals\" subcommand specified"); + "No \"ex\" subcommand specified"); } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Unknown \"internals\" subcommand '%s'", subcommand_name); + "Unknown \"ex\" subcommand '%s'", subcommand_name); } exit_status = EXIT_FAILURE; diff --git a/src/app/rpmostree-builtin-start-daemon.c b/src/app/rpmostree-builtin-start-daemon.c index 8ddba4b57b..72ec67b5d8 100644 --- a/src/app/rpmostree-builtin-start-daemon.c +++ b/src/app/rpmostree-builtin-start-daemon.c @@ -31,7 +31,7 @@ #include #include "libglnx.h" -#include "rpmostree-internals-builtins.h" +#include "rpmostree-builtins.h" #include "rpmostree-util.h" #include "rpmostreed-daemon.h" #include "rpmostree-libbuiltin.h" diff --git a/src/app/rpmostree-builtins.h b/src/app/rpmostree-builtins.h index c81c288132..aa9e9c657e 100644 --- a/src/app/rpmostree-builtins.h +++ b/src/app/rpmostree-builtins.h @@ -73,6 +73,7 @@ BUILTINPROTO(container); BUILTINPROTO(pkg_add); BUILTINPROTO(pkg_remove); BUILTINPROTO(start_daemon); +BUILTINPROTO(ex); #undef BUILTINPROTO diff --git a/src/app/rpmostree-internals-builtin-unpack.c b/src/app/rpmostree-ex-builtin-unpack.c similarity index 90% rename from src/app/rpmostree-internals-builtin-unpack.c rename to src/app/rpmostree-ex-builtin-unpack.c index 25cd097767..3554866a54 100644 --- a/src/app/rpmostree-internals-builtin-unpack.c +++ b/src/app/rpmostree-ex-builtin-unpack.c @@ -29,7 +29,7 @@ #include #include -#include "rpmostree-internals-builtins.h" +#include "rpmostree-ex-builtins.h" #include "rpmostree-util.h" #include "rpmostree-core.h" #include "rpmostree-libbuiltin.h" @@ -51,11 +51,11 @@ static GOptionEntry option_entries[] = { }; int -rpmostree_internals_builtin_unpack (int argc, - char **argv, - RpmOstreeCommandInvocation *invocation, - GCancellable *cancellable, - GError **error) +rpmostree_ex_builtin_unpack (int argc, + char **argv, + RpmOstreeCommandInvocation *invocation, + GCancellable *cancellable, + GError **error) { int exit_status = EXIT_FAILURE; g_autoptr(GOptionContext) context = g_option_context_new ("REPO RPM"); diff --git a/src/app/rpmostree-internals-builtins.h b/src/app/rpmostree-ex-builtins.h similarity index 75% rename from src/app/rpmostree-internals-builtins.h rename to src/app/rpmostree-ex-builtins.h index 95f3280325..9b57006529 100644 --- a/src/app/rpmostree-internals-builtins.h +++ b/src/app/rpmostree-ex-builtins.h @@ -26,8 +26,7 @@ G_BEGIN_DECLS -gboolean rpmostree_internals_builtin_unpack (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); -gboolean rpmostree_internals_builtin_start_daemon (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +gboolean rpmostree_ex_builtin_unpack (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); G_END_DECLS From 2b876e9dcce9b95b3e34d7899c13e3b2d9e22bec Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 15 Mar 2017 21:09:36 -0400 Subject: [PATCH 5/6] =?UTF-8?q?main:=20Move=20"rpm-ostree=20container"=20?= =?UTF-8?q?=E2=86=92=20"rpm-ostree=20ex=20container"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now all of our "experimental" bits are under one roof, so we get consistent handling for them. --- src/app/main.c | 2 -- src/app/rpmostree-builtin-ex.c | 3 +++ tests/check/test-ucontainer.sh | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/app/main.c b/src/app/main.c index a8248ac99a..72cfc73ead 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -68,8 +68,6 @@ static RpmOstreeCommand commands[] = { /* Experimental */ { "ex", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL, rpmostree_builtin_ex }, - { "container", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL, - rpmostree_builtin_container }, /* Hidden */ { "start-daemon", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT | RPM_OSTREE_BUILTIN_FLAG_HIDDEN, diff --git a/src/app/rpmostree-builtin-ex.c b/src/app/rpmostree-builtin-ex.c index fd50523eeb..38d05e2cf3 100644 --- a/src/app/rpmostree-builtin-ex.c +++ b/src/app/rpmostree-builtin-ex.c @@ -21,11 +21,14 @@ #include "config.h" #include "rpmostree-ex-builtins.h" +#include "rpmostree-container-builtins.h" #include "rpmostree-rpm-util.h" static RpmOstreeCommand ex_subcommands[] = { { "unpack", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, rpmostree_ex_builtin_unpack }, + { "container", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD, + rpmostree_builtin_container }, { NULL, 0, NULL } }; diff --git a/tests/check/test-ucontainer.sh b/tests/check/test-ucontainer.sh index 9acff77982..0c9d790b7a 100755 --- a/tests/check/test-ucontainer.sh +++ b/tests/check/test-ucontainer.sh @@ -23,7 +23,7 @@ set -euo pipefail echo "1..2" -rpm-ostree container init +rpm-ostree ex container init cp ${commondir}/compose/test-repo.repo rpmmd.repos.d @@ -34,7 +34,7 @@ packages=empty repos=test-repo EOF -rpm-ostree container assemble empty.conf +rpm-ostree ex container assemble empty.conf assert_has_dir roots/empty.0 ostree --repo=repo rev-parse empty echo "ok assemble" @@ -44,7 +44,7 @@ cat >nobranch.conf <err.txt; then +if rpm-ostree ex container assemble nobranch.conf 2>err.txt; then assert_not_reached "nobranch.conf" fi @@ -54,7 +54,7 @@ ref=empty packages= repos=test-repo EOF -if rpm-ostree container assemble nopackages.conf 2>err.txt; then +if rpm-ostree ex container assemble nopackages.conf 2>err.txt; then assert_not_reached "nopackages.conf" fi @@ -63,7 +63,7 @@ cat >norepos.conf <err.txt; then +if rpm-ostree ex container assemble norepos.conf 2>err.txt; then assert_not_reached "norepos.conf" fi @@ -73,7 +73,7 @@ ref=notfound packages=notfound repos=test-repo EOF -if rpm-ostree container assemble notfound.conf 2>err.txt; then +if rpm-ostree ex container assemble notfound.conf 2>err.txt; then assert_not_reached "notfound.conf" fi From b6dcc09f452b56d1be929b749f9d35d61140425f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 16 Mar 2017 13:28:44 -0400 Subject: [PATCH 6/6] =?UTF-8?q?fixup!=20app:=20Rename=20internals=20?= =?UTF-8?q?=E2=86=92=20ex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/rpmostree-builtin-ex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/rpmostree-builtin-ex.c b/src/app/rpmostree-builtin-ex.c index 38d05e2cf3..13effc3ba3 100644 --- a/src/app/rpmostree-builtin-ex.c +++ b/src/app/rpmostree-builtin-ex.c @@ -83,7 +83,7 @@ rpmostree_builtin_ex (int argc, char **argv, if (!subcommand->name) { - g_autoptr(GOptionContext) context = internals_option_context_new_with_commands (); + g_autoptr(GOptionContext) context = ex_option_context_new_with_commands (); g_autofree char *help = NULL; (void) rpmostree_option_context_parse (context, NULL,