main: Distinguish "preview" and "experimental" commands

Let's say package layering is "preview" - we show it in help, but
marked `(preview)`.

Whereas the `container` and `internals` builtins this patch calls
"experimental" - we don't show them in help even.

Both get a warning message when executed.

Closes: #354
Approved by: jlebon
This commit is contained in:
Colin Walters 2016-06-27 20:41:38 -04:00 committed by Atomic Bot
parent 000b0675bd
commit 5b6bf4576f

View File

@ -32,19 +32,28 @@
#include "rpmostree-builtins.h"
#include "libgsystem.h"
#include "libglnx.h"
static RpmOstreeCommand commands[] = {
static RpmOstreeCommand supported_commands[] = {
#ifdef HAVE_COMPOSE_TOOLING
{ "compose", rpmostree_builtin_compose },
#endif
{ "db", rpmostree_builtin_db },
{ "deploy", rpmostree_builtin_deploy },
{ "pkg-add", rpmostree_builtin_pkg_add },
{ "pkg-remove", rpmostree_builtin_pkg_remove },
{ "rebase", rpmostree_builtin_rebase },
{ "rollback", rpmostree_builtin_rollback },
{ "status", rpmostree_builtin_status },
{ "upgrade", rpmostree_builtin_upgrade },
{ NULL }
};
static RpmOstreeCommand preview_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 }
@ -68,7 +77,7 @@ static GOptionEntry daemon_entries[] = {
static GOptionContext *
option_context_new_with_commands (void)
{
RpmOstreeCommand *command = commands;
RpmOstreeCommand *command = supported_commands;
GOptionContext *context;
GString *summary;
@ -78,12 +87,14 @@ option_context_new_with_commands (void)
while (command->name != NULL)
{
/* Internals will remain hidden always, container will possibly
* get promoted at some point. For now, it's an easter egg.
*/
if (!g_str_equal (command->name, "internals")
&& !g_str_equal (command->name, "container"))
g_string_append_printf (summary, "\n %s", command->name);
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);
command++;
}
@ -177,6 +188,32 @@ on_sigint (gpointer user_data)
return FALSE;
}
static RpmOstreeCommand *
lookup_command_of_type (RpmOstreeCommand *commands,
const char *name,
const char *type)
{
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;
}
command++;
}
return NULL;
}
int
main (int argc,
@ -232,15 +269,15 @@ main (int argc,
if (g_strcmp0 (command_name, "rpm") == 0)
command_name = "db";
command = commands;
while (command->name)
{
if (g_strcmp0 (command_name, command->name) == 0)
break;
command++;
}
command = lookup_command_of_type (supported_commands, command_name, NULL);
if (!command->fn)
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)
{
GOptionContext *context;
gs_free char *help = NULL;