Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app: Rename internals → ex #683

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile-rpm-ostree.am
Original file line number Diff line number Diff line change
@@ -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)
147 changes: 68 additions & 79 deletions src/app/main.c
Original file line number Diff line number Diff line change
@@ -33,42 +33,45 @@

#include "libglnx.h"

static RpmOstreeCommand supported_commands[] = {
static RpmOstreeCommand 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 },
{ NULL }
};

static RpmOstreeCommand preview_commands[] = {
{ NULL }
};

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

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

static RpmOstreeCommand hidden_commands[] = {
{ "start-daemon", rpmostree_builtin_start_daemon },
{ "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 },
/* 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 | RPM_OSTREE_BUILTIN_FLAG_HIDDEN,
rpmostree_builtin_pkg_remove },
/* Experimental */
{ "ex", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL,
rpmostree_builtin_ex },
/* 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 }
};

@@ -90,7 +93,7 @@ static GOptionEntry daemon_entries[] = {
static GOptionContext *
option_context_new_with_commands (void)
{
RpmOstreeCommand *command = supported_commands;
RpmOstreeCommand *command = commands;
GOptionContext *context;
GString *summary;

@@ -100,14 +103,10 @@ option_context_new_with_commands (void)

while (command->name != NULL)
{
g_string_append_printf (summary, "\n %s", command->name);
command++;
}

command = preview_commands;
while (command->name != NULL)
{
g_string_append_printf (summary, "\n %s (preview)", 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++;
}

@@ -123,15 +122,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);
@@ -213,40 +212,40 @@ 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;
}

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think invocation->command->name will always be ex here. What we actually want is command_name below, right? Alternatively, the commands under ex also need to be flagged as EXPERIMENTAL but not ex itself? Hmm, kinda messy.

the properties of a command are now consistently represented as flags

That makes sense, though for EXPERIMENTAL, since only ex will use it, it might be cleaner to drop that flag and print the notice in rpmostree_builtin_ex()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess...though I dunno that it's really valuable to polish this extensively - time I spend tweaking the fine details of the code here is time not spent on actually writing livefs or tests etc.

}

for (in = 1, out = 1; in < argc; in++, out++)
{
/* The non-option is the command, take it out of the arguments */
@@ -294,24 +293,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 (preview_commands, command_name, "a preview");

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)
{
@@ -320,8 +308,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 +330,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)
9 changes: 5 additions & 4 deletions src/app/rpmostree-builtin-cleanup.c
Original file line number Diff line number Diff line change
@@ -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))
17 changes: 11 additions & 6 deletions src/app/rpmostree-builtin-compose.c
Original file line number Diff line number Diff line change
@@ -29,8 +29,9 @@
#include <glib/gi18n.h>

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

static GOptionContext *
@@ -58,14 +59,16 @@ 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;
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)
@@ -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;
24 changes: 14 additions & 10 deletions src/app/rpmostree-builtin-container.c
Original file line number Diff line number Diff line change
@@ -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,15 +59,14 @@ 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;
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)
{
@@ -79,13 +81,13 @@ rpmostree_builtin_container (int argc, char **argv, GCancellable *cancellable, G
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,
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
invocation,
cancellable,
NULL,
NULL);

if (subcommand_name == NULL)
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
@@ -107,7 +109,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;
Loading