From 298c151fd8f78e6c3f6f199cd32981ae3d311828 Mon Sep 17 00:00:00 2001 From: Ruixin Bao Date: Tue, 17 Oct 2017 17:25:04 +0000 Subject: [PATCH] ostree: move flags into command struct, pass down through builtins This is a similar approach as https://github.com/projectatomic/rpm-ostree/commit/12c34bb2491a07079c911ef26401fee939e5573c. One thing to note is when we parse the admin related functions, we still keep the old admin related flags, and added a new parameter to represent the command struct. This allows us to identify the caller of the function, making it easier for us to possibly deduplicate the subcommand handling in the future. A similar approach is done in rpm-ostree: https://github.com/projectatomic/rpm-ostree/commit/83aeb018c1012c7a43783c09b74ec71bc9c45826 This also makes it easier for us to change the prototype of the function. If we want to add something new in the future, we won't need to touch every prototype. Closes: #1267 Approved by: cgwalters --- src/ostree/main.c | 83 +++++++++++++------ src/ostree/ot-admin-builtin-cleanup.c | 4 +- src/ostree/ot-admin-builtin-deploy.c | 4 +- src/ostree/ot-admin-builtin-diff.c | 4 +- src/ostree/ot-admin-builtin-init-fs.c | 8 +- src/ostree/ot-admin-builtin-instutil.c | 30 ++++--- src/ostree/ot-admin-builtin-os-init.c | 4 +- src/ostree/ot-admin-builtin-set-origin.c | 4 +- src/ostree/ot-admin-builtin-status.c | 4 +- src/ostree/ot-admin-builtin-switch.c | 4 +- src/ostree/ot-admin-builtin-undeploy.c | 4 +- src/ostree/ot-admin-builtin-unlock.c | 4 +- src/ostree/ot-admin-builtin-upgrade.c | 4 +- src/ostree/ot-admin-builtins.h | 34 ++++---- ...ot-admin-instutil-builtin-grub2-generate.c | 4 +- ...-instutil-builtin-selinux-ensure-labeled.c | 4 +- .../ot-admin-instutil-builtin-set-kargs.c | 4 +- src/ostree/ot-admin-instutil-builtins.h | 6 +- src/ostree/ot-builtin-admin.c | 57 +++++++------ src/ostree/ot-builtin-cat.c | 4 +- src/ostree/ot-builtin-checkout.c | 4 +- src/ostree/ot-builtin-checksum.c | 4 +- src/ostree/ot-builtin-commit.c | 4 +- src/ostree/ot-builtin-config.c | 4 +- src/ostree/ot-builtin-create-usb.c | 3 +- src/ostree/ot-builtin-diff.c | 4 +- src/ostree/ot-builtin-export.c | 4 +- src/ostree/ot-builtin-find-remotes.c | 3 +- src/ostree/ot-builtin-fsck.c | 4 +- src/ostree/ot-builtin-gpg-sign.c | 4 +- src/ostree/ot-builtin-init.c | 4 +- src/ostree/ot-builtin-log.c | 3 +- src/ostree/ot-builtin-ls.c | 4 +- src/ostree/ot-builtin-prune.c | 4 +- src/ostree/ot-builtin-pull-local.c | 4 +- src/ostree/ot-builtin-pull.c | 4 +- src/ostree/ot-builtin-refs.c | 4 +- src/ostree/ot-builtin-remote.c | 51 +++++++----- src/ostree/ot-builtin-reset.c | 3 +- src/ostree/ot-builtin-rev-parse.c | 4 +- src/ostree/ot-builtin-show.c | 4 +- src/ostree/ot-builtin-static-delta.c | 44 +++++----- src/ostree/ot-builtin-summary.c | 4 +- src/ostree/ot-builtin-trivial-httpd.c | 2 +- src/ostree/ot-builtins.h | 2 +- src/ostree/ot-main.c | 14 ++-- src/ostree/ot-main.h | 19 ++++- src/ostree/ot-remote-builtin-add-cookie.c | 4 +- src/ostree/ot-remote-builtin-add.c | 4 +- src/ostree/ot-remote-builtin-delete-cookie.c | 4 +- src/ostree/ot-remote-builtin-delete.c | 4 +- src/ostree/ot-remote-builtin-gpg-import.c | 4 +- src/ostree/ot-remote-builtin-list-cookies.c | 4 +- src/ostree/ot-remote-builtin-list.c | 4 +- src/ostree/ot-remote-builtin-refs.c | 4 +- src/ostree/ot-remote-builtin-show-url.c | 4 +- src/ostree/ot-remote-builtin-summary.c | 4 +- src/ostree/ot-remote-builtins.h | 26 +++--- 58 files changed, 316 insertions(+), 236 deletions(-) diff --git a/src/ostree/main.c b/src/ostree/main.c index ef8f1f8a..4ae261d6 100644 --- a/src/ostree/main.c +++ b/src/ostree/main.c @@ -32,62 +32,93 @@ #include "ot-builtins.h" static OstreeCommand commands[] = { - { "admin", ostree_builtin_admin , + /* Note: all admin related commands have + * no_repo as their command flag, but each + * admin command may have their own + * admin flag + */ + { "admin", OSTREE_BUILTIN_FLAG_NO_REPO, + ostree_builtin_admin, "Commands that needs admin privilege" }, - { "cat", ostree_builtin_cat, + { "cat", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_cat, "Concatenate contents of files"}, - { "checkout", ostree_builtin_checkout, + { "checkout", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_checkout, "Check out a commit into a filesystem tree" }, - { "checksum", ostree_builtin_checksum, + { "checksum", OSTREE_BUILTIN_FLAG_NO_REPO, + ostree_builtin_checksum, "Checksum a file or directory" }, - { "commit", ostree_builtin_commit, + { "commit", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_commit, "Commit a new revision" }, - { "config", ostree_builtin_config, + { "config", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_config, "Change repo configuration settings" }, - { "diff", ostree_builtin_diff, + { "diff", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_diff, "Compare directory TARGETDIR against revision REV"}, - { "export", ostree_builtin_export, + { "export", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_export, "Stream COMMIT to stdout in tar format" }, #ifdef OSTREE_ENABLE_EXPERIMENTAL_API - { "find-remotes", ostree_builtin_find_remotes, + { "find-remotes", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_find_remotes, "Find remotes to serve the given refs" }, - { "create-usb", ostree_builtin_create_usb, + { "create-usb", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_create_usb, "Copy the refs to a USB stick" }, #endif - { "fsck", ostree_builtin_fsck, + { "fsck", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_fsck, "Check the repository for consistency" }, - { "gpg-sign", ostree_builtin_gpg_sign, + { "gpg-sign", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_gpg_sign, "Sign a commit" }, - { "init", ostree_builtin_init, + { "init", OSTREE_BUILTIN_FLAG_NO_CHECK, + ostree_builtin_init, "Initialize a new empty repository" }, - { "log", ostree_builtin_log, + { "log", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_log, "Show log starting at commit or ref" }, - { "ls", ostree_builtin_ls, + { "ls", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_ls, "List file paths" }, - { "prune", ostree_builtin_prune, + { "prune", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_prune, "Search for unreachable objects" }, - { "pull-local", ostree_builtin_pull_local, + { "pull-local", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_pull_local, "Copy data from SRC_REPO" }, #ifdef HAVE_LIBCURL_OR_LIBSOUP - { "pull", ostree_builtin_pull, + { "pull", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_pull, "Download data from remote repository" }, #endif - { "refs", ostree_builtin_refs, + { "refs", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_refs, "List refs" }, - { "remote", ostree_builtin_remote, + { "remote", OSTREE_BUILTIN_FLAG_NO_REPO, + ostree_builtin_remote, "Remote commands that may involve internet access" }, - { "reset", ostree_builtin_reset, + { "reset", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_reset, "Reset a REF to a previous COMMIT" }, - { "rev-parse", ostree_builtin_rev_parse, + { "rev-parse", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_rev_parse, "Output the target of a rev" }, - { "show", ostree_builtin_show, + { "show", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_show, "Output a metadata object" }, - { "static-delta", ostree_builtin_static_delta, + { "static-delta", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_static_delta, "Static delta related commands" }, - { "summary", ostree_builtin_summary, + { "summary", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_summary, "Manage summary metadata" }, #if defined(HAVE_LIBSOUP) && defined(BUILDOPT_ENABLE_TRIVIAL_HTTPD_CMDLINE) - { "trivial-httpd", ostree_builtin_trivial_httpd, + { "trivial-httpd", OSTREE_BUILTIN_FLAG_NONE, + ostree_builtin_trivial_httpd, NULL }, #endif { NULL } diff --git a/src/ostree/ot-admin-builtin-cleanup.c b/src/ostree/ot-admin-builtin-cleanup.c index 954f8d8a..bc7a724b 100644 --- a/src/ostree/ot-admin-builtin-cleanup.c +++ b/src/ostree/ot-admin-builtin-cleanup.c @@ -38,7 +38,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_cleanup (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_cleanup (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeSysroot) sysroot = NULL; @@ -48,7 +48,7 @@ ot_admin_builtin_cleanup (int argc, char **argv, GCancellable *cancellable, GErr if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) goto out; if (!ostree_sysroot_cleanup (sysroot, cancellable, error)) diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c index 10ac57de..6bfc09ee 100644 --- a/src/ostree/ot-admin-builtin-deploy.c +++ b/src/ostree/ot-admin-builtin-deploy.c @@ -60,7 +60,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { __attribute__((cleanup(_ostree_kernel_args_cleanup))) OstreeKernelArgs *kargs = NULL; @@ -70,7 +70,7 @@ ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GErro g_autoptr(OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) return FALSE; if (argc < 2) diff --git a/src/ostree/ot-admin-builtin-diff.c b/src/ostree/ot-admin-builtin-diff.c index 6afe4fae..ec8f692e 100644 --- a/src/ostree/ot-admin-builtin-diff.c +++ b/src/ostree/ot-admin-builtin-diff.c @@ -41,7 +41,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeSysroot) sysroot = NULL; @@ -60,7 +60,7 @@ ot_admin_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) goto out; if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname, diff --git a/src/ostree/ot-admin-builtin-init-fs.c b/src/ostree/ot-admin-builtin-init-fs.c index 3ef9017f..e1c0e439 100644 --- a/src/ostree/ot-admin-builtin-init-fs.c +++ b/src/ostree/ot-admin-builtin-init-fs.c @@ -38,15 +38,15 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_init_fs (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_init_fs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = g_option_context_new ("PATH - Initialize a root filesystem"); if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | - OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED | - OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, - NULL, cancellable, error)) + OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED | + OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, + invocation, NULL, cancellable, error)) return FALSE; if (argc < 2) diff --git a/src/ostree/ot-admin-builtin-instutil.c b/src/ostree/ot-admin-builtin-instutil.c index 428c0a2c..0ee3b3f2 100644 --- a/src/ostree/ot-admin-builtin-instutil.c +++ b/src/ostree/ot-admin-builtin-instutil.c @@ -28,28 +28,25 @@ #include -typedef struct { - const char *name; - gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error); - const char *description; -} OstreeAdminInstUtilCommand; - -static OstreeAdminInstUtilCommand admin_instutil_subcommands[] = { +static OstreeCommand admin_instutil_subcommands[] = { #ifdef HAVE_SELINUX - { "selinux-ensure-labeled", ot_admin_instutil_builtin_selinux_ensure_labeled, + { "selinux-ensure-labeled", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_instutil_builtin_selinux_ensure_labeled, "Relabel all or part of a deployment" }, #endif - { "set-kargs", ot_admin_instutil_builtin_set_kargs, + { "set-kargs", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_instutil_builtin_set_kargs, "Set new kernel command line arguments(Not stable)" }, - { "grub2-generate", ot_admin_instutil_builtin_grub2_generate, + { "grub2-generate", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_instutil_builtin_grub2_generate, "Generate GRUB2 configuration from given BLS entries" }, - { NULL, NULL, NULL } + { NULL, 0, NULL, NULL } }; static GOptionContext * ostree_admin_instutil_option_context_new_with_commands (void) { - OstreeAdminInstUtilCommand *command = admin_instutil_subcommands; + OstreeCommand *command = admin_instutil_subcommands; GOptionContext *context = g_option_context_new ("COMMAND"); g_autoptr(GString) summary = g_string_new ("Builtin \"admin instutil\" Commands:"); @@ -69,7 +66,7 @@ ostree_admin_instutil_option_context_new_with_commands (void) } gboolean -ot_admin_builtin_instutil (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_instutil (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { const char *subcommand_name = NULL; int in, out; @@ -97,7 +94,7 @@ ot_admin_builtin_instutil (int argc, char **argv, GCancellable *cancellable, GEr argc = out; - OstreeAdminInstUtilCommand *subcommand = admin_instutil_subcommands; + OstreeCommand *subcommand = admin_instutil_subcommands; while (subcommand->name) { if (g_strcmp0 (subcommand_name, subcommand->name) == 0) @@ -113,7 +110,7 @@ ot_admin_builtin_instutil (int argc, char **argv, GCancellable *cancellable, GEr /* This will not return for some options (e.g. --version). */ if (ostree_admin_option_context_parse (context, NULL, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, - NULL, cancellable, error)) + invocation, NULL, cancellable, error)) { if (subcommand_name == NULL) { @@ -135,7 +132,8 @@ ot_admin_builtin_instutil (int argc, char **argv, GCancellable *cancellable, GEr g_autofree char *prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name); g_set_prgname (prgname); - if (!subcommand->fn (argc, argv, cancellable, error)) + OstreeCommandInvocation sub_invocation = { .command = subcommand }; + if (!subcommand->fn (argc, argv, &sub_invocation, cancellable, error)) return FALSE; return TRUE; diff --git a/src/ostree/ot-admin-builtin-os-init.c b/src/ostree/ot-admin-builtin-os-init.c index b325ab32..a6a11f99 100644 --- a/src/ostree/ot-admin-builtin-os-init.c +++ b/src/ostree/ot-admin-builtin-os-init.c @@ -38,7 +38,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_os_init (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeSysroot) sysroot = NULL; @@ -49,7 +49,7 @@ ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GErr if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) goto out; if (!ostree_sysroot_ensure_initialized (sysroot, cancellable, error)) diff --git a/src/ostree/ot-admin-builtin-set-origin.c b/src/ostree/ot-admin-builtin-set-origin.c index 0332d882..0f6fd259 100644 --- a/src/ostree/ot-admin-builtin-set-origin.c +++ b/src/ostree/ot-admin-builtin-set-origin.c @@ -45,7 +45,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_set_origin (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_set_origin (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GOptionContext) context = NULL; @@ -60,7 +60,7 @@ ot_admin_builtin_set_origin (int argc, char **argv, GCancellable *cancellable, G if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) goto out; if (argc < 3) diff --git a/src/ostree/ot-admin-builtin-status.c b/src/ostree/ot-admin-builtin-status.c index f076c592..b88c2fba 100644 --- a/src/ostree/ot-admin-builtin-status.c +++ b/src/ostree/ot-admin-builtin-status.c @@ -85,7 +85,7 @@ out: } gboolean -ot_admin_builtin_status (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeSysroot) sysroot = NULL; @@ -104,7 +104,7 @@ ot_admin_builtin_status (int argc, char **argv, GCancellable *cancellable, GErro if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) goto out; if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error)) diff --git a/src/ostree/ot-admin-builtin-switch.c b/src/ostree/ot-admin-builtin-switch.c index 56e731b2..1b1082d5 100644 --- a/src/ostree/ot-admin-builtin-switch.c +++ b/src/ostree/ot-admin-builtin-switch.c @@ -44,14 +44,14 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_switch (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_switch (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = g_option_context_new ("REF - Construct new tree from REF and deploy it"); g_autoptr(OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) return FALSE; if (argc < 2) diff --git a/src/ostree/ot-admin-builtin-undeploy.c b/src/ostree/ot-admin-builtin-undeploy.c index 6ca8e3a3..3bddd6cb 100644 --- a/src/ostree/ot-admin-builtin-undeploy.c +++ b/src/ostree/ot-admin-builtin-undeploy.c @@ -37,7 +37,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_undeploy (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_undeploy (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeSysroot) sysroot = NULL; @@ -50,7 +50,7 @@ ot_admin_builtin_undeploy (int argc, char **argv, GCancellable *cancellable, GEr if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) return FALSE; if (argc < 2) diff --git a/src/ostree/ot-admin-builtin-unlock.c b/src/ostree/ot-admin-builtin-unlock.c index 1b6d9203..cb3598fd 100644 --- a/src/ostree/ot-admin-builtin-unlock.c +++ b/src/ostree/ot-admin-builtin-unlock.c @@ -43,7 +43,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_unlock (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_unlock (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GOptionContext) context = NULL; @@ -55,7 +55,7 @@ ot_admin_builtin_unlock (int argc, char **argv, GCancellable *cancellable, GErro if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) goto out; if (argc > 1) diff --git a/src/ostree/ot-admin-builtin-upgrade.c b/src/ostree/ot-admin-builtin-upgrade.c index dfda4d5f..c0542f3e 100644 --- a/src/ostree/ot-admin-builtin-upgrade.c +++ b/src/ostree/ot-admin-builtin-upgrade.c @@ -54,14 +54,14 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_builtin_upgrade (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = g_option_context_new ("Construct new tree from current origin and deploy it, if it changed"); g_autoptr(OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) return FALSE; if (opt_pull_only && opt_deploy_only) diff --git a/src/ostree/ot-admin-builtins.h b/src/ostree/ot-admin-builtins.h index 75cd1448..1d62daf8 100644 --- a/src/ostree/ot-admin-builtins.h +++ b/src/ostree/ot-admin-builtins.h @@ -25,19 +25,25 @@ G_BEGIN_DECLS -gboolean ot_admin_builtin_selinux_ensure_labeled (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_install (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_instutil (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_init_fs (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_undeploy (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_cleanup (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_unlock (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_status (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_set_origin (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_switch (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GError **error); +#define BUILTINPROTO(name) gboolean ot_admin_builtin_ ## name (int argc, char **argv, \ + OstreeCommandInvocation *invocation, \ + GCancellable *cancellable, GError **error) + +BUILTINPROTO(selinux_ensure_labeled); +BUILTINPROTO(os_init); +BUILTINPROTO(install); +BUILTINPROTO(instutil); +BUILTINPROTO(init_fs); +BUILTINPROTO(undeploy); +BUILTINPROTO(deploy); +BUILTINPROTO(cleanup); +BUILTINPROTO(unlock); +BUILTINPROTO(status); +BUILTINPROTO(set_origin); +BUILTINPROTO(diff); +BUILTINPROTO(switch); +BUILTINPROTO(upgrade); + +#undef BUILTINPROTO G_END_DECLS diff --git a/src/ostree/ot-admin-instutil-builtin-grub2-generate.c b/src/ostree/ot-admin-instutil-builtin-grub2-generate.c index 64d2ae2a..a7eb0d4f 100644 --- a/src/ostree/ot-admin-instutil-builtin-grub2-generate.c +++ b/src/ostree/ot-admin-instutil-builtin-grub2-generate.c @@ -38,7 +38,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; guint bootversion; @@ -49,7 +49,7 @@ ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, GCancellable *c if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) goto out; if (argc >= 2) diff --git a/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c b/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c index 135bcf42..ca3fab17 100644 --- a/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c +++ b/src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c @@ -183,7 +183,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *policy_name; @@ -200,7 +200,7 @@ ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, GCancel if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) goto out; deployments = ostree_sysroot_get_deployments (sysroot); diff --git a/src/ostree/ot-admin-instutil-builtin-set-kargs.c b/src/ostree/ot-admin-instutil-builtin-set-kargs.c index f8db6c6b..7419581c 100644 --- a/src/ostree/ot-admin-instutil-builtin-set-kargs.c +++ b/src/ostree/ot-admin-instutil-builtin-set-kargs.c @@ -48,7 +48,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_instutil_builtin_set_kargs (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_admin_instutil_builtin_set_kargs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; guint i; @@ -62,7 +62,7 @@ ot_admin_instutil_builtin_set_kargs (int argc, char **argv, GCancellable *cancel if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, - &sysroot, cancellable, error)) + invocation, &sysroot, cancellable, error)) goto out; deployments = ostree_sysroot_get_deployments (sysroot); diff --git a/src/ostree/ot-admin-instutil-builtins.h b/src/ostree/ot-admin-instutil-builtins.h index 748a7938..b0277e71 100644 --- a/src/ostree/ot-admin-instutil-builtins.h +++ b/src/ostree/ot-admin-instutil-builtins.h @@ -23,8 +23,8 @@ G_BEGIN_DECLS -gboolean ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_instutil_builtin_set_kargs (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, GCancellable *cancellable, GError **error); +gboolean ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +gboolean ot_admin_instutil_builtin_set_kargs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +gboolean ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/ostree/ot-builtin-admin.c b/src/ostree/ot-builtin-admin.c index ba9dc28d..17033ecf 100644 --- a/src/ostree/ot-builtin-admin.c +++ b/src/ostree/ot-builtin-admin.c @@ -30,44 +30,50 @@ #include -typedef struct { - const char *name; - gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error); - const char *description; -} OstreeAdminCommand; - -static OstreeAdminCommand admin_subcommands[] = { - { "cleanup", ot_admin_builtin_cleanup, +static OstreeCommand admin_subcommands[] = { + { "cleanup", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_cleanup, "Delete untagged deployments and repository objects" }, - { "config-diff", ot_admin_builtin_diff, + { "config-diff", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_diff, "Diff current /etc configuration versus default" }, - { "deploy", ot_admin_builtin_deploy, + { "deploy", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_deploy, "Checkout revision REFSPEC as the new default deployment" }, - { "init-fs", ot_admin_builtin_init_fs, + { "init-fs", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_init_fs, "Initialize a root filesystem" }, - { "instutil", ot_admin_builtin_instutil, + { "instutil", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_instutil, "Provide instutil commands, allow admin to change boot configuration and relabel selinux " }, - { "os-init", ot_admin_builtin_os_init, + { "os-init", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_os_init, "Initialize empty state for given operating system" }, - { "set-origin", ot_admin_builtin_set_origin, + { "set-origin", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_set_origin, "Set Origin and create a new origin file" }, - { "status", ot_admin_builtin_status, + { "status", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_status, "List deployments" }, - { "switch", ot_admin_builtin_switch, + { "switch", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_switch, "Construct new tree from REF and deploy it" }, - { "undeploy", ot_admin_builtin_undeploy, + { "undeploy", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_undeploy, "Delete deployment INDEX" }, - { "unlock", ot_admin_builtin_unlock, + { "unlock", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_unlock, "Make the current deployment mutable (as a hotfix or development)" }, - { "upgrade", ot_admin_builtin_upgrade, + { "upgrade", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_admin_builtin_upgrade, "Construct new tree from current origin and deploy it, if it changed" }, - { NULL, NULL, NULL } + { NULL, 0, NULL, NULL } }; static GOptionContext * ostree_admin_option_context_new_with_commands (void) { - OstreeAdminCommand *command = admin_subcommands; + OstreeCommand *command = admin_subcommands; GOptionContext *context = g_option_context_new ("--print-current-dir|COMMAND"); g_autoptr(GString) summary = g_string_new ("Builtin \"admin\" Commands:"); @@ -86,11 +92,11 @@ ostree_admin_option_context_new_with_commands (void) } gboolean -ostree_builtin_admin (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_admin (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *subcommand_name = NULL; - OstreeAdminCommand *subcommand; + OstreeCommand *subcommand; g_autofree char *prgname = NULL; int in, out; @@ -141,7 +147,7 @@ ostree_builtin_admin (int argc, char **argv, GCancellable *cancellable, GError * /* This will not return for some options (e.g. --version). */ if (ostree_admin_option_context_parse (context, NULL, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT, - NULL, cancellable, error)) + invocation, NULL, cancellable, error)) { if (subcommand_name == NULL) { @@ -164,7 +170,8 @@ ostree_builtin_admin (int argc, char **argv, GCancellable *cancellable, GError * prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name); g_set_prgname (prgname); - if (!subcommand->fn (argc, argv, cancellable, error)) + OstreeCommandInvocation sub_invocation = { .command = subcommand }; + if (!subcommand->fn (argc, argv, &sub_invocation, cancellable, error)) goto out; ret = TRUE; diff --git a/src/ostree/ot-builtin-cat.c b/src/ostree/ot-builtin-cat.c index 6f2c466c..88bd4fdb 100644 --- a/src/ostree/ot-builtin-cat.c +++ b/src/ostree/ot-builtin-cat.c @@ -55,11 +55,11 @@ cat_one_file (GFile *f, } gboolean -ostree_builtin_cat (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_cat (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = g_option_context_new ("COMMIT PATH... - Concatenate contents of files"); g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) return FALSE; if (argc <= 2) diff --git a/src/ostree/ot-builtin-checkout.c b/src/ostree/ot-builtin-checkout.c index e774713e..79718c9c 100644 --- a/src/ostree/ot-builtin-checkout.c +++ b/src/ostree/ot-builtin-checkout.c @@ -279,7 +279,7 @@ process_many_checkouts (OstreeRepo *repo, } gboolean -ostree_builtin_checkout (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_checkout (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -290,7 +290,7 @@ ostree_builtin_checkout (int argc, char **argv, GCancellable *cancellable, GErro context = g_option_context_new ("COMMIT [DESTINATION] - Check out a commit into a filesystem tree"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (opt_disable_fsync) diff --git a/src/ostree/ot-builtin-checksum.c b/src/ostree/ot-builtin-checksum.c index 008c4fe7..24689ac6 100644 --- a/src/ostree/ot-builtin-checksum.c +++ b/src/ostree/ot-builtin-checksum.c @@ -66,12 +66,12 @@ on_checksum_received (GObject *obj, } gboolean -ostree_builtin_checksum (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_checksum (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = g_option_context_new ("PATH - Checksum a file or directory"); if (!ostree_option_context_parse (context, options, &argc, &argv, - OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, error)) + invocation, NULL, cancellable, error)) return FALSE; if (argc < 2) diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index b10e8d2d..7df1dfe1 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -407,7 +407,7 @@ fill_bindings (OstreeRepo *repo, } gboolean -ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -433,7 +433,7 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError context = g_option_context_new ("[PATH] - Commit a new revision"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) diff --git a/src/ostree/ot-builtin-config.c b/src/ostree/ot-builtin-config.c index 6813305c..94e36465 100644 --- a/src/ostree/ot-builtin-config.c +++ b/src/ostree/ot-builtin-config.c @@ -56,7 +56,7 @@ split_key_string (const char *k, } gboolean -ostree_builtin_config (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -70,7 +70,7 @@ ostree_builtin_config (int argc, char **argv, GCancellable *cancellable, GError context = g_option_context_new ("(get KEY|set KEY VALUE) - Change repo configuration settings"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (argc < 2) diff --git a/src/ostree/ot-builtin-create-usb.c b/src/ostree/ot-builtin-create-usb.c index 97b0059a..fcde36c0 100644 --- a/src/ostree/ot-builtin-create-usb.c +++ b/src/ostree/ot-builtin-create-usb.c @@ -43,6 +43,7 @@ static GOptionEntry options[] = gboolean ostree_builtin_create_usb (int argc, char **argv, + OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -55,7 +56,7 @@ ostree_builtin_create_usb (int argc, /* Parse options. */ g_autoptr(OstreeRepo) src_repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &src_repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &src_repo, cancellable, error)) return FALSE; if (argc < 2) diff --git a/src/ostree/ot-builtin-diff.c b/src/ostree/ot-builtin-diff.c index 465e2506..9cd7141b 100644 --- a/src/ostree/ot-builtin-diff.c +++ b/src/ostree/ot-builtin-diff.c @@ -126,7 +126,7 @@ object_set_total_size (OstreeRepo *repo, } gboolean -ostree_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GOptionContext) context = NULL; @@ -142,7 +142,7 @@ ostree_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError ** context = g_option_context_new ("REV TARGETDIR - Compare directory TARGETDIR against revision REV"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (argc < 2) diff --git a/src/ostree/ot-builtin-export.c b/src/ostree/ot-builtin-export.c index 7967bf6c..83656d04 100644 --- a/src/ostree/ot-builtin-export.c +++ b/src/ostree/ot-builtin-export.c @@ -62,7 +62,7 @@ propagate_libarchive_error (GError **error, #endif gboolean -ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_export (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -79,7 +79,7 @@ ostree_builtin_export (int argc, char **argv, GCancellable *cancellable, GError context = g_option_context_new ("COMMIT - Stream COMMIT to stdout in tar format"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; #ifdef HAVE_LIBARCHIVE diff --git a/src/ostree/ot-builtin-find-remotes.c b/src/ostree/ot-builtin-find-remotes.c index daeea38b..3cf6c153 100644 --- a/src/ostree/ot-builtin-find-remotes.c +++ b/src/ostree/ot-builtin-find-remotes.c @@ -120,6 +120,7 @@ collection_ref_free0 (OstreeCollectionRef *ref) gboolean ostree_builtin_find_remotes (int argc, char **argv, + OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -136,7 +137,7 @@ ostree_builtin_find_remotes (int argc, context = g_option_context_new ("COLLECTION-ID REF [COLLECTION-ID REF...] - Find remotes to serve the given refs"); /* Parse options. */ - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) return FALSE; if (!ostree_ensure_repo_writable (repo, error)) diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c index 28320985..81ac3218 100644 --- a/src/ostree/ot-builtin-fsck.c +++ b/src/ostree/ot-builtin-fsck.c @@ -214,13 +214,13 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo, } gboolean -ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(OstreeRepo) repo = NULL; gboolean found_corruption = FALSE; g_autoptr(GOptionContext) context = g_option_context_new ("- Check the repository for consistency"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) return FALSE; if (!opt_quiet) diff --git a/src/ostree/ot-builtin-gpg-sign.c b/src/ostree/ot-builtin-gpg-sign.c index 451d0f46..3eeeeb01 100644 --- a/src/ostree/ot-builtin-gpg-sign.c +++ b/src/ostree/ot-builtin-gpg-sign.c @@ -200,7 +200,7 @@ out: } gboolean -ostree_builtin_gpg_sign (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_gpg_sign (int argc, char **argv,OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -212,7 +212,7 @@ ostree_builtin_gpg_sign (int argc, char **argv, GCancellable *cancellable, GErro context = g_option_context_new ("COMMIT KEY-ID... - Sign a commit"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (argc < 2) diff --git a/src/ostree/ot-builtin-init.c b/src/ostree/ot-builtin-init.c index 7b72620a..c7729e47 100644 --- a/src/ostree/ot-builtin-init.c +++ b/src/ostree/ot-builtin-init.c @@ -45,7 +45,7 @@ static GOptionEntry options[] = { }; gboolean -ostree_builtin_init (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_init (int argc, char **argv,OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -54,7 +54,7 @@ ostree_builtin_init (int argc, char **argv, GCancellable *cancellable, GError ** context = g_option_context_new ("- Initialize a new empty repository"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NO_CHECK, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (!ostree_repo_mode_from_string (opt_mode, &mode, error)) diff --git a/src/ostree/ot-builtin-log.c b/src/ostree/ot-builtin-log.c index 5fda4ee7..ee4b37d0 100644 --- a/src/ostree/ot-builtin-log.c +++ b/src/ostree/ot-builtin-log.c @@ -82,6 +82,7 @@ out: gboolean ostree_builtin_log (int argc, char **argv, + OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -94,7 +95,7 @@ ostree_builtin_log (int argc, context = g_option_context_new ("REF - Show log starting at commit or ref"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (opt_raw) diff --git a/src/ostree/ot-builtin-ls.c b/src/ostree/ot-builtin-ls.c index ba22d3c3..bababaad 100644 --- a/src/ostree/ot-builtin-ls.c +++ b/src/ostree/ot-builtin-ls.c @@ -240,7 +240,7 @@ print_one_argument (OstreeRepo *repo, } gboolean -ostree_builtin_ls (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_ls (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -251,7 +251,7 @@ ostree_builtin_ls (int argc, char **argv, GCancellable *cancellable, GError **er context = g_option_context_new ("COMMIT [PATH...] - List file paths"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (argc <= 1) diff --git a/src/ostree/ot-builtin-prune.c b/src/ostree/ot-builtin-prune.c index f5ab5960..ab3816bc 100644 --- a/src/ostree/ot-builtin-prune.c +++ b/src/ostree/ot-builtin-prune.c @@ -144,11 +144,11 @@ traverse_keep_younger_than (OstreeRepo *repo, const char *checksum, } gboolean -ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_prune (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = g_option_context_new ("- Search for unreachable objects"); g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) return FALSE; if (!opt_no_prune && !ostree_ensure_repo_writable (repo, error)) diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c index 8d4e8d60..b907b5aa 100644 --- a/src/ostree/ot-builtin-pull-local.c +++ b/src/ostree/ot-builtin-pull-local.c @@ -64,7 +64,7 @@ noninteractive_console_progress_changed (OstreeAsyncProgress *progress, } gboolean -ostree_builtin_pull_local (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_pull_local (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GOptionContext) context = NULL; @@ -78,7 +78,7 @@ ostree_builtin_pull_local (int argc, char **argv, GCancellable *cancellable, GEr context = g_option_context_new ("SRC_REPO [REFS...] - Copy data from SRC_REPO"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c index e67d5993..719c4d5b 100644 --- a/src/ostree/ot-builtin-pull.c +++ b/src/ostree/ot-builtin-pull.c @@ -143,7 +143,7 @@ noninteractive_console_progress_changed (OstreeAsyncProgress *progress, } gboolean -ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_pull (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -157,7 +157,7 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError ** context = g_option_context_new ("REMOTE [BRANCH...] - Download data from remote repository"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c index 1b4ead7d..68befc74 100644 --- a/src/ostree/ot-builtin-refs.c +++ b/src/ostree/ot-builtin-refs.c @@ -261,7 +261,7 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab } gboolean -ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GOptionContext) context = NULL; @@ -270,7 +270,7 @@ ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError ** context = g_option_context_new ("[PREFIX] - List refs"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (argc >= 2) diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c index 0b1c02a2..0be878cc 100644 --- a/src/ostree/ot-builtin-remote.c +++ b/src/ostree/ot-builtin-remote.c @@ -25,42 +25,46 @@ #include "ot-builtins.h" #include "ot-remote-builtins.h" -typedef struct { - const char *name; - gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error); - const char *description; -} OstreeRemoteCommand; - -static OstreeRemoteCommand remote_subcommands[] = { - { "add", ot_remote_builtin_add, +static OstreeCommand remote_subcommands[] = { + { "add", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_remote_builtin_add, "Add a remote repository" }, - { "delete", ot_remote_builtin_delete, + { "delete", OSTREE_BUILTIN_FLAG_NO_REPO, + ot_remote_builtin_delete, "Delete a remote repository" }, - { "show-url", ot_remote_builtin_show_url, + { "show-url", OSTREE_BUILTIN_FLAG_NONE, + ot_remote_builtin_show_url, "Show remote repository URL" }, - { "list", ot_remote_builtin_list, + { "list", OSTREE_BUILTIN_FLAG_NONE, + ot_remote_builtin_list, "List remote repository names" }, - { "gpg-import", ot_remote_builtin_gpg_import, + { "gpg-import", OSTREE_BUILTIN_FLAG_NONE, + ot_remote_builtin_gpg_import, "Import GPG keys" }, #ifdef HAVE_LIBSOUP - { "add-cookie", ot_remote_builtin_add_cookie, + { "add-cookie", OSTREE_BUILTIN_FLAG_NONE, + ot_remote_builtin_add_cookie, "Add a cookie to remote" }, - { "delete-cookie", ot_remote_builtin_delete_cookie, + { "delete-cookie", OSTREE_BUILTIN_FLAG_NONE, + ot_remote_builtin_delete_cookie, "Remove one cookie from remote" }, - { "list-cookies", ot_remote_builtin_list_cookies, + { "list-cookies", OSTREE_BUILTIN_FLAG_NONE, + ot_remote_builtin_list_cookies, "Show remote repository cookies" }, #endif - { "refs", ot_remote_builtin_refs, + { "refs", OSTREE_BUILTIN_FLAG_NONE, + ot_remote_builtin_refs, "List remote refs" }, - { "summary", ot_remote_builtin_summary, + { "summary", OSTREE_BUILTIN_FLAG_NONE, + ot_remote_builtin_summary, "Show remote summary" }, - { NULL, NULL, NULL } + { NULL, 0, NULL, NULL } }; static GOptionContext * remote_option_context_new_with_commands (void) { - OstreeRemoteCommand *subcommand = remote_subcommands; + OstreeCommand *subcommand = remote_subcommands; GOptionContext *context = g_option_context_new ("COMMAND"); g_autoptr(GString) summary = g_string_new ("Builtin \"remote\" Commands:"); @@ -80,9 +84,9 @@ remote_option_context_new_with_commands (void) } gboolean -ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { - OstreeRemoteCommand *subcommand; + OstreeCommand *subcommand; const char *subcommand_name = NULL; g_autofree char *prgname = NULL; gboolean ret = FALSE; @@ -128,7 +132,7 @@ ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError /* This will not return for some options (e.g. --version). */ if (ostree_option_context_parse (context, NULL, &argc, &argv, - OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, + invocation, NULL, cancellable, error)) { if (subcommand_name == NULL) @@ -152,7 +156,8 @@ ostree_builtin_remote (int argc, char **argv, GCancellable *cancellable, GError prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name); g_set_prgname (prgname); - if (!subcommand->fn (argc, argv, cancellable, error)) + OstreeCommandInvocation sub_invocation = { .command = subcommand }; + if (!subcommand->fn (argc, argv, &sub_invocation, cancellable, error)) goto out; ret = TRUE; diff --git a/src/ostree/ot-builtin-reset.c b/src/ostree/ot-builtin-reset.c index ae1da7cb..f465e0cf 100644 --- a/src/ostree/ot-builtin-reset.c +++ b/src/ostree/ot-builtin-reset.c @@ -38,6 +38,7 @@ static GOptionEntry options[] = { gboolean ostree_builtin_reset (int argc, char **argv, + OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -52,7 +53,7 @@ ostree_builtin_reset (int argc, /* FIXME: Add support for collection–refs. */ context = g_option_context_new ("REF COMMIT - Reset a REF to a previous COMMIT"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) diff --git a/src/ostree/ot-builtin-rev-parse.c b/src/ostree/ot-builtin-rev-parse.c index 060bcdc9..cf1da5a6 100644 --- a/src/ostree/ot-builtin-rev-parse.c +++ b/src/ostree/ot-builtin-rev-parse.c @@ -36,7 +36,7 @@ static GOptionEntry options[] = { }; gboolean -ostree_builtin_rev_parse (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_rev_parse (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -47,7 +47,7 @@ ostree_builtin_rev_parse (int argc, char **argv, GCancellable *cancellable, GErr context = g_option_context_new ("REV - Output the target of a rev"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (argc < 2) diff --git a/src/ostree/ot-builtin-show.c b/src/ostree/ot-builtin-show.c index c4b586b1..79dfd29e 100644 --- a/src/ostree/ot-builtin-show.c +++ b/src/ostree/ot-builtin-show.c @@ -226,12 +226,12 @@ print_if_found (OstreeRepo *repo, } gboolean -ostree_builtin_show (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = g_option_context_new ("OBJECT - Output a metadata object"); g_autoptr(OstreeRepo) repo = NULL; - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) return FALSE; if (argc <= 1) diff --git a/src/ostree/ot-builtin-static-delta.c b/src/ostree/ot-builtin-static-delta.c index b2af1d66..c9b6b456 100644 --- a/src/ostree/ot-builtin-static-delta.c +++ b/src/ostree/ot-builtin-static-delta.c @@ -39,7 +39,7 @@ static gboolean opt_inline; static gboolean opt_disable_bsdiff; static gboolean opt_if_not_exists; -#define BUILTINPROTO(name) static gboolean ot_static_delta_builtin_ ## name (int argc, char **argv, GCancellable *cancellable, GError **error) +#define BUILTINPROTO(name) static gboolean ot_static_delta_builtin_ ## name (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) BUILTINPROTO(list); BUILTINPROTO(show); @@ -50,17 +50,22 @@ BUILTINPROTO(apply_offline); #undef BUILTINPROTO static OstreeCommand static_delta_subcommands[] = { - { "list", ot_static_delta_builtin_list, + { "list", OSTREE_BUILTIN_FLAG_NONE, + ot_static_delta_builtin_list, "List static delta files" }, - { "show", ot_static_delta_builtin_show, + { "show", OSTREE_BUILTIN_FLAG_NONE, + ot_static_delta_builtin_show, "Dump information on a delta" }, - { "delete", ot_static_delta_builtin_delete, + { "delete", OSTREE_BUILTIN_FLAG_NONE, + ot_static_delta_builtin_delete, "Remove a delta" }, - { "generate", ot_static_delta_builtin_generate, + { "generate", OSTREE_BUILTIN_FLAG_NONE, + ot_static_delta_builtin_generate, "Generate static delta files" }, - { "apply-offline", ot_static_delta_builtin_apply_offline, + { "apply-offline", OSTREE_BUILTIN_FLAG_NONE, + ot_static_delta_builtin_apply_offline, "Apply static delta file" }, - { NULL, NULL, NULL } + { NULL, 0, NULL, NULL } }; /* ATTENTION: @@ -118,12 +123,12 @@ static_delta_usage (char **argv, } static gboolean -ot_static_delta_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_list (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(OstreeRepo) repo = NULL; g_autoptr(GOptionContext) context = g_option_context_new ("- list static delta files"); if (!ostree_option_context_parse (context, list_options, &argc, &argv, - OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + invocation, &repo, cancellable, error)) return FALSE; g_autoptr(GPtrArray) delta_names = NULL; @@ -142,7 +147,7 @@ ot_static_delta_builtin_list (int argc, char **argv, GCancellable *cancellable, } static gboolean -ot_static_delta_builtin_show (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GOptionContext) context = NULL; @@ -151,7 +156,7 @@ ot_static_delta_builtin_show (int argc, char **argv, GCancellable *cancellable, context = g_option_context_new ("- Dump information on a delta"); - if (!ostree_option_context_parse (context, list_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (argc < 3) @@ -172,7 +177,7 @@ ot_static_delta_builtin_show (int argc, char **argv, GCancellable *cancellable, } static gboolean -ot_static_delta_builtin_delete (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GOptionContext) context = NULL; @@ -181,7 +186,7 @@ ot_static_delta_builtin_delete (int argc, char **argv, GCancellable *cancellable context = g_option_context_new ("- Remove a delta"); - if (!ostree_option_context_parse (context, list_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (argc < 3) @@ -203,14 +208,14 @@ ot_static_delta_builtin_delete (int argc, char **argv, GCancellable *cancellable static gboolean -ot_static_delta_builtin_generate (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; context = g_option_context_new ("[TO] - Generate static delta files"); - if (!ostree_option_context_parse (context, generate_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, generate_options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) @@ -352,7 +357,7 @@ ot_static_delta_builtin_generate (int argc, char **argv, GCancellable *cancellab } static gboolean -ot_static_delta_builtin_apply_offline (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *patharg; @@ -361,7 +366,7 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, GCancellable *canc g_autoptr(OstreeRepo) repo = NULL; context = g_option_context_new ("- Apply static delta file"); - if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, invocation, &repo, cancellable, error)) goto out; if (!ostree_ensure_repo_writable (repo, error)) @@ -392,7 +397,7 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, GCancellable *canc } gboolean -ostree_builtin_static_delta (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_static_delta (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { gboolean want_help = FALSE; const char *cmdname = NULL; @@ -443,5 +448,6 @@ ostree_builtin_static_delta (int argc, char **argv, GCancellable *cancellable, G g_autofree char *prgname = g_strdup_printf ("%s %s", g_get_prgname (), cmdname); g_set_prgname (prgname); - return command->fn (argc, argv, cancellable, error); + OstreeCommandInvocation sub_invocation = { .command = command }; + return command->fn (argc, argv, &sub_invocation, cancellable, error); } diff --git a/src/ostree/ot-builtin-summary.c b/src/ostree/ot-builtin-summary.c index 15998efd..a1d0fe56 100644 --- a/src/ostree/ot-builtin-summary.c +++ b/src/ostree/ot-builtin-summary.c @@ -81,7 +81,7 @@ build_additional_metadata (const char * const *args, } gboolean -ostree_builtin_summary (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -89,7 +89,7 @@ ostree_builtin_summary (int argc, char **argv, GCancellable *cancellable, GError context = g_option_context_new ("Manage summary metadata"); - if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error)) return FALSE; if (opt_update) diff --git a/src/ostree/ot-builtin-trivial-httpd.c b/src/ostree/ot-builtin-trivial-httpd.c index 972cf1ad..37487a76 100644 --- a/src/ostree/ot-builtin-trivial-httpd.c +++ b/src/ostree/ot-builtin-trivial-httpd.c @@ -25,7 +25,7 @@ #include "otutil.h" gboolean -ostree_builtin_trivial_httpd (int argc, char **argv, GCancellable *cancellable, GError **error) +ostree_builtin_trivial_httpd (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GPtrArray) new_argv = g_ptr_array_new (); diff --git a/src/ostree/ot-builtins.h b/src/ostree/ot-builtins.h index ccb47f60..e5864a46 100644 --- a/src/ostree/ot-builtins.h +++ b/src/ostree/ot-builtins.h @@ -27,7 +27,7 @@ G_BEGIN_DECLS -#define BUILTINPROTO(name) gboolean ostree_builtin_ ## name (int argc, char **argv, GCancellable *cancellable, GError **error) +#define BUILTINPROTO(name) gboolean ostree_builtin_ ## name (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) BUILTINPROTO(admin); BUILTINPROTO(cat); diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c index d81b802c..c63cff7e 100644 --- a/src/ostree/ot-main.c +++ b/src/ostree/ot-main.c @@ -171,7 +171,7 @@ ostree_run (int argc, ostree_option_context_new_with_commands (commands); /* This will not return for some options (e.g. --version). */ - if (ostree_option_context_parse (context, NULL, &argc, &argv, OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, &error)) + if (ostree_option_context_parse (context, NULL, &argc, &argv, NULL, NULL, cancellable, &error)) { if (command_name == NULL) { @@ -193,8 +193,8 @@ ostree_run (int argc, prgname = g_strdup_printf ("%s %s", g_get_prgname (), command_name); g_set_prgname (prgname); #endif - - if (!command->fn (argc, argv, cancellable, &error)) + OstreeCommandInvocation invocation = { .command = command }; + if (!command->fn (argc, argv, &invocation, cancellable, &error)) goto out; success = TRUE; @@ -296,13 +296,14 @@ ostree_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, int *argc, char ***argv, - OstreeBuiltinFlags flags, + OstreeCommandInvocation *invocation, OstreeRepo **out_repo, GCancellable *cancellable, GError **error) { g_autoptr(OstreeRepo) repo = NULL; - + /* When invocation is NULL, it usually means an error occurs, do not fetch repo this case */ + const OstreeBuiltinFlags flags = invocation ? invocation->command->flags : OSTREE_BUILTIN_FLAG_NO_REPO; /* Entries are listed in --help output in the order added. We add the * main entries ourselves so that we can add the --repo entry first. */ @@ -366,6 +367,7 @@ ostree_admin_option_context_parse (GOptionContext *context, int *argc, char ***argv, OstreeAdminBuiltinFlags flags, + OstreeCommandInvocation *invocation, OstreeSysroot **out_sysroot, GCancellable *cancellable, GError **error) @@ -376,7 +378,7 @@ ostree_admin_option_context_parse (GOptionContext *context, g_option_context_add_main_entries (context, global_admin_entries, NULL); if (!ostree_option_context_parse (context, main_entries, argc, argv, - OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, error)) + invocation, NULL, cancellable, error)) return FALSE; if (!opt_print_current_dir && (flags & OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT)) diff --git a/src/ostree/ot-main.h b/src/ostree/ot-main.h index d795e531..26f9f6e1 100644 --- a/src/ostree/ot-main.h +++ b/src/ostree/ot-main.h @@ -37,12 +37,26 @@ typedef enum { OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT = (1 << 2), } OstreeAdminBuiltinFlags; + +typedef struct OstreeCommandInvocation OstreeCommandInvocation; + typedef struct { const char *name; - gboolean (*fn) (int argc, char **argv, GCancellable *cancellable, GError **error); + OstreeBuiltinFlags flags; + gboolean (*fn) (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); const char *description; } OstreeCommand; +/* This is a similar implementation as + * https://github.com/projectatomic/rpm-ostree/commit/12c34bb2491a07079c911ef26401fee939e5573c. + * + * In the future if we want to add something new we won't need to + * touch every prototype + */ +struct OstreeCommandInvocation { + OstreeCommand *command; +}; + int ostree_run (int argc, char **argv, OstreeCommand *commands, GError **error); int ostree_usage (OstreeCommand *commands, gboolean is_error); @@ -58,7 +72,7 @@ gboolean ostree_parse_sysroot_or_repo_option (GOptionContext *context, gboolean ostree_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, int *argc, char ***argv, - OstreeBuiltinFlags flags, + OstreeCommandInvocation *invocation, OstreeRepo **out_repo, GCancellable *cancellable, GError **error); @@ -66,6 +80,7 @@ gboolean ostree_admin_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, int *argc, char ***argv, OstreeAdminBuiltinFlags flags, + OstreeCommandInvocation *invocation, OstreeSysroot **out_sysroot, GCancellable *cancellable, GError **error); diff --git a/src/ostree/ot-remote-builtin-add-cookie.c b/src/ostree/ot-remote-builtin-add-cookie.c index 764d2fc3..051d0389 100644 --- a/src/ostree/ot-remote-builtin-add-cookie.c +++ b/src/ostree/ot-remote-builtin-add-cookie.c @@ -37,12 +37,12 @@ static GOptionEntry option_entries[] = { }; gboolean -ot_remote_builtin_add_cookie (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_add_cookie (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = g_option_context_new ("NAME DOMAIN PATH COOKIE_NAME VALUE - Add a cookie to remote"); g_autoptr(OstreeRepo) repo = NULL; if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + invocation, &repo, cancellable, error)) return FALSE; if (argc < 6) diff --git a/src/ostree/ot-remote-builtin-add.c b/src/ostree/ot-remote-builtin-add.c index f0990795..080fd501 100644 --- a/src/ostree/ot-remote-builtin-add.c +++ b/src/ostree/ot-remote-builtin-add.c @@ -57,7 +57,7 @@ static GOptionEntry option_entries[] = { }; gboolean -ot_remote_builtin_add (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_add (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeSysroot) sysroot = NULL; @@ -72,7 +72,7 @@ ot_remote_builtin_add (int argc, char **argv, GCancellable *cancellable, GError context = g_option_context_new ("NAME [metalink=|mirrorlist=]URL [BRANCH...] - Add a remote repository"); if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, error)) + invocation, NULL, cancellable, error)) goto out; if (!ostree_parse_sysroot_or_repo_option (context, opt_sysroot, opt_repo, diff --git a/src/ostree/ot-remote-builtin-delete-cookie.c b/src/ostree/ot-remote-builtin-delete-cookie.c index 17f356a1..726f3ab6 100644 --- a/src/ostree/ot-remote-builtin-delete-cookie.c +++ b/src/ostree/ot-remote-builtin-delete-cookie.c @@ -38,13 +38,13 @@ static GOptionEntry option_entries[] = { }; gboolean -ot_remote_builtin_delete_cookie (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_delete_cookie (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(OstreeRepo) repo = NULL; g_autoptr(GOptionContext) context = g_option_context_new ("NAME DOMAIN PATH COOKIE_NAME- Remove one cookie from remote"); if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + invocation, &repo, cancellable, error)) return FALSE; if (argc < 5) diff --git a/src/ostree/ot-remote-builtin-delete.c b/src/ostree/ot-remote-builtin-delete.c index d7ad6bb5..54cba2bf 100644 --- a/src/ostree/ot-remote-builtin-delete.c +++ b/src/ostree/ot-remote-builtin-delete.c @@ -41,13 +41,13 @@ static GOptionEntry option_entries[] = { }; gboolean -ot_remote_builtin_delete (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = g_option_context_new ("NAME - Delete a remote repository"); if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, error)) + invocation, NULL, cancellable, error)) return FALSE; g_autoptr(OstreeSysroot) sysroot = NULL; diff --git a/src/ostree/ot-remote-builtin-gpg-import.c b/src/ostree/ot-remote-builtin-gpg-import.c index 6edcf321..eca2fee6 100644 --- a/src/ostree/ot-remote-builtin-gpg-import.c +++ b/src/ostree/ot-remote-builtin-gpg-import.c @@ -95,7 +95,7 @@ out: } gboolean -ot_remote_builtin_gpg_import (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_gpg_import (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -108,7 +108,7 @@ ot_remote_builtin_gpg_import (int argc, char **argv, GCancellable *cancellable, context = g_option_context_new ("NAME [KEY-ID...] - Import GPG keys"); if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + invocation, &repo, cancellable, error)) goto out; if (argc < 2) diff --git a/src/ostree/ot-remote-builtin-list-cookies.c b/src/ostree/ot-remote-builtin-list-cookies.c index 99d76346..7b7ba5d4 100644 --- a/src/ostree/ot-remote-builtin-list-cookies.c +++ b/src/ostree/ot-remote-builtin-list-cookies.c @@ -37,13 +37,13 @@ static GOptionEntry option_entries[] = { }; gboolean -ot_remote_builtin_list_cookies (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_list_cookies (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(OstreeRepo) repo = NULL; g_autoptr(GOptionContext) context = g_option_context_new ("NAME - Show remote repository cookies"); if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + invocation, &repo, cancellable, error)) return FALSE; if (argc < 2) diff --git a/src/ostree/ot-remote-builtin-list.c b/src/ostree/ot-remote-builtin-list.c index fea5e420..589b97bb 100644 --- a/src/ostree/ot-remote-builtin-list.c +++ b/src/ostree/ot-remote-builtin-list.c @@ -35,7 +35,7 @@ static GOptionEntry option_entries[] = { }; gboolean -ot_remote_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_list (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -46,7 +46,7 @@ ot_remote_builtin_list (int argc, char **argv, GCancellable *cancellable, GError context = g_option_context_new ("- List remote repository names"); if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + invocation, &repo, cancellable, error)) goto out; remotes = ostree_repo_remote_list (repo, &n_remotes); diff --git a/src/ostree/ot-remote-builtin-refs.c b/src/ostree/ot-remote-builtin-refs.c index bffc1985..71d5b5d6 100644 --- a/src/ostree/ot-remote-builtin-refs.c +++ b/src/ostree/ot-remote-builtin-refs.c @@ -37,7 +37,7 @@ static GOptionEntry option_entries[] = { }; gboolean -ot_remote_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_refs (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -48,7 +48,7 @@ ot_remote_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError context = g_option_context_new ("NAME - List remote refs"); if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + invocation, &repo, cancellable, error)) goto out; if (argc < 2) diff --git a/src/ostree/ot-remote-builtin-show-url.c b/src/ostree/ot-remote-builtin-show-url.c index 7ce0572e..0f3e56f9 100644 --- a/src/ostree/ot-remote-builtin-show-url.c +++ b/src/ostree/ot-remote-builtin-show-url.c @@ -34,7 +34,7 @@ static GOptionEntry option_entries[] = { }; gboolean -ot_remote_builtin_show_url (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_show_url (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -45,7 +45,7 @@ ot_remote_builtin_show_url (int argc, char **argv, GCancellable *cancellable, GE context = g_option_context_new ("NAME - Show remote repository URL"); if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + invocation, &repo, cancellable, error)) goto out; if (argc < 2) diff --git a/src/ostree/ot-remote-builtin-summary.c b/src/ostree/ot-remote-builtin-summary.c index 30aedc2d..8d501589 100644 --- a/src/ostree/ot-remote-builtin-summary.c +++ b/src/ostree/ot-remote-builtin-summary.c @@ -41,7 +41,7 @@ static GOptionEntry option_entries[] = { }; gboolean -ot_remote_builtin_summary (int argc, char **argv, GCancellable *cancellable, GError **error) +ot_remote_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(OstreeRepo) repo = NULL; @@ -55,7 +55,7 @@ ot_remote_builtin_summary (int argc, char **argv, GCancellable *cancellable, GEr context = g_option_context_new ("NAME - Show remote summary"); if (!ostree_option_context_parse (context, option_entries, &argc, &argv, - OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) + invocation, &repo, cancellable, error)) goto out; if (argc < 2) diff --git a/src/ostree/ot-remote-builtins.h b/src/ostree/ot-remote-builtins.h index c61fcc07..ce788524 100644 --- a/src/ostree/ot-remote-builtins.h +++ b/src/ostree/ot-remote-builtins.h @@ -23,17 +23,23 @@ G_BEGIN_DECLS -gboolean ot_remote_builtin_add (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_remote_builtin_delete (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_remote_builtin_gpg_import (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_remote_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error); +#define BUILTINPROTO(name) gboolean ot_remote_builtin_ ## name (int argc, char **argv, \ + OstreeCommandInvocation *invocation, \ + GCancellable *cancellable, GError **error) + +BUILTINPROTO(add); +BUILTINPROTO(delete); +BUILTINPROTO(gpg_import); +BUILTINPROTO(list); #ifdef HAVE_LIBSOUP -gboolean ot_remote_builtin_add_cookie (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_remote_builtin_list_cookies (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_remote_builtin_delete_cookie (int argc, char **argv, GCancellable *cancellable, GError **error); +BUILTINPROTO(add_cookie); +BUILTINPROTO(list_cookies); +BUILTINPROTO(delete_cookie); #endif -gboolean ot_remote_builtin_show_url (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_remote_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **error); -gboolean ot_remote_builtin_summary (int argc, char **argv, GCancellable *cancellable, GError **error); +BUILTINPROTO(show_url); +BUILTINPROTO(refs); +BUILTINPROTO(summary); + +#undef BUILTINPROTO G_END_DECLS