Skip to content

Commit

Permalink
CLI: use proper command name in experimental notice
Browse files Browse the repository at this point in the history
This is a follow-up to coreos#683. All the experimental commands will be under
`rpm-ostree ex`, so we remove the flag and instead print the notice
before dispatching the subcommand, where we can print the correct name.
  • Loading branch information
jlebon committed Mar 16, 2017
1 parent 710ea30 commit 8d9103e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
18 changes: 2 additions & 16 deletions src/app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ static RpmOstreeCommand commands[] = {
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,
{ "ex", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_HIDDEN,
rpmostree_builtin_ex },
/* Hidden */
{ "start-daemon", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD | RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT |
Expand Down Expand Up @@ -104,8 +103,7 @@ option_context_new_with_commands (void)
while (command->name != NULL)
{
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))
if (!is_hidden)
g_string_append_printf (summary, "\n %s", command->name);
command++;
}
Expand Down Expand Up @@ -234,18 +232,6 @@ rpmostree_subcommand_parse (int *inout_argc,
const char *command_name = NULL;
int in, out;

if (invocation && (invocation->command->flags & RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL) > 0)
{
const int is_tty = isatty (1);
const char *bold_prefix = is_tty ? "\x1b[1m" : "";
const char *bold_suffix = is_tty ? "\x1b[0m" : "";

g_assert (invocation);

g_printerr ("%snotice%s: %s is an experimental command and subject to change.\n",
bold_prefix, bold_suffix, invocation->command->name);
}

for (in = 1, out = 1; in < argc; in++, out++)
{
/* The non-option is the command, take it out of the arguments */
Expand Down
10 changes: 9 additions & 1 deletion src/app/rpmostree-builtin-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,18 @@ rpmostree_builtin_ex (int argc, char **argv,
goto out;
}


prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
g_set_prgname (prgname);

{ RpmOstreeCommandInvocation sub_invocation = { .command = subcommand };
{ const int is_tty = isatty (1);
const char *bold_prefix = is_tty ? "\x1b[1m" : "";
const char *bold_suffix = is_tty ? "\x1b[0m" : "";

g_printerr ("%snotice%s: \"%s\" is an experimental command and subject to change.\n",
bold_prefix, bold_suffix, subcommand->name);

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

Expand Down
3 changes: 1 addition & 2 deletions src/app/rpmostree-builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ typedef enum {
RPM_OSTREE_BUILTIN_FLAG_NONE = 0,
RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD = 1 << 0,
RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT = 1 << 1,
RPM_OSTREE_BUILTIN_FLAG_EXPERIMENTAL = 1 << 2,
RPM_OSTREE_BUILTIN_FLAG_HIDDEN = 1 << 3,
RPM_OSTREE_BUILTIN_FLAG_HIDDEN = 1 << 2,
} RpmOstreeBuiltinFlags;

typedef struct RpmOstreeCommand RpmOstreeCommand;
Expand Down

0 comments on commit 8d9103e

Please sign in to comment.