bin/static-delta: Convert to new style and tweak output
Convert the whole file to new style. Also tweak the help outputs to make it similar enough to the other commands for tests to pass. Of course, we should just centralize all subcommand handling the same way it was done in rpm-ostree, though let's punt on that for now. Closes: #1126 Approved by: cgwalters
This commit is contained in:
parent
4efab3feb0
commit
225bbdf002
|
|
@ -100,48 +100,41 @@ static_delta_usage (char **argv,
|
||||||
else
|
else
|
||||||
print_func = g_print;
|
print_func = g_print;
|
||||||
|
|
||||||
print_func ("usage: ostree static-delta\n");
|
print_func ("Usage:\n");
|
||||||
print_func ("Builtin commands:\n");
|
print_func (" ostree static-delta [OPTION...] COMMAND\n\n");
|
||||||
|
print_func ("Builtin \"static-delta\" Commands:\n");
|
||||||
|
|
||||||
while (command->name)
|
while (command->name)
|
||||||
{
|
{
|
||||||
print_func (" %s\n", command->name);
|
print_func (" %s\n", command->name);
|
||||||
command++;
|
command++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_func ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ot_static_delta_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error)
|
ot_static_delta_builtin_list (int argc, char **argv, GCancellable *cancellable, GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_autoptr(GPtrArray) delta_names = NULL;
|
|
||||||
guint i;
|
|
||||||
g_autoptr(GOptionContext) context = NULL;
|
|
||||||
g_autoptr(OstreeRepo) repo = NULL;
|
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))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
context = g_option_context_new ("LIST - list static delta files");
|
g_autoptr(GPtrArray) delta_names = NULL;
|
||||||
|
|
||||||
if (!ostree_option_context_parse (context, list_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!ostree_repo_list_static_delta_names (repo, &delta_names, cancellable, error))
|
if (!ostree_repo_list_static_delta_names (repo, &delta_names, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
if (delta_names->len == 0)
|
if (delta_names->len == 0)
|
||||||
{
|
|
||||||
g_print ("(No static deltas)\n");
|
g_print ("(No static deltas)\n");
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; i < delta_names->len; i++)
|
for (guint i = 0; i < delta_names->len; i++)
|
||||||
{
|
|
||||||
g_print ("%s\n", (char*)delta_names->pdata[i]);
|
g_print ("%s\n", (char*)delta_names->pdata[i]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -152,7 +145,7 @@ ot_static_delta_builtin_show (int argc, char **argv, GCancellable *cancellable,
|
||||||
g_autoptr(OstreeRepo) repo = NULL;
|
g_autoptr(OstreeRepo) repo = NULL;
|
||||||
const char *delta_id = NULL;
|
const char *delta_id = NULL;
|
||||||
|
|
||||||
context = g_option_context_new ("SHOW - Dump information on a delta");
|
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, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -182,7 +175,7 @@ ot_static_delta_builtin_delete (int argc, char **argv, GCancellable *cancellable
|
||||||
g_autoptr(OstreeRepo) repo = NULL;
|
g_autoptr(OstreeRepo) repo = NULL;
|
||||||
const char *delta_id = NULL;
|
const char *delta_id = NULL;
|
||||||
|
|
||||||
context = g_option_context_new ("DELETE - Remove a delta");
|
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, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -212,7 +205,7 @@ ot_static_delta_builtin_generate (int argc, char **argv, GCancellable *cancellab
|
||||||
g_autoptr(GOptionContext) context = NULL;
|
g_autoptr(GOptionContext) context = NULL;
|
||||||
g_autoptr(OstreeRepo) repo = NULL;
|
g_autoptr(OstreeRepo) repo = NULL;
|
||||||
|
|
||||||
context = g_option_context_new ("GENERATE [TO] - Generate static delta files");
|
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, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -363,7 +356,7 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, GCancellable *canc
|
||||||
g_autoptr(GOptionContext) context = NULL;
|
g_autoptr(GOptionContext) context = NULL;
|
||||||
g_autoptr(OstreeRepo) repo = NULL;
|
g_autoptr(OstreeRepo) repo = NULL;
|
||||||
|
|
||||||
context = g_option_context_new ("APPLY-OFFLINE - Apply static delta file");
|
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, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -397,13 +390,9 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, GCancellable *canc
|
||||||
gboolean
|
gboolean
|
||||||
ostree_builtin_static_delta (int argc, char **argv, GCancellable *cancellable, GError **error)
|
ostree_builtin_static_delta (int argc, char **argv, GCancellable *cancellable, GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
OstreeCommand *command = NULL;
|
|
||||||
const char *cmdname = NULL;
|
|
||||||
int i;
|
|
||||||
gboolean want_help = FALSE;
|
gboolean want_help = FALSE;
|
||||||
|
const char *cmdname = NULL;
|
||||||
for (i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (argv[i][0] != '-')
|
if (argv[i][0] != '-')
|
||||||
{
|
{
|
||||||
|
|
@ -420,11 +409,10 @@ ostree_builtin_static_delta (int argc, char **argv, GCancellable *cancellable, G
|
||||||
if (!cmdname && !want_help)
|
if (!cmdname && !want_help)
|
||||||
{
|
{
|
||||||
static_delta_usage (argv, TRUE);
|
static_delta_usage (argv, TRUE);
|
||||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
return glnx_throw (error, "No command specified");
|
||||||
"No command specified");
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OstreeCommand *command = NULL;
|
||||||
if (cmdname)
|
if (cmdname)
|
||||||
{
|
{
|
||||||
command = static_delta_subcommands;
|
command = static_delta_subcommands;
|
||||||
|
|
@ -439,22 +427,17 @@ ostree_builtin_static_delta (int argc, char **argv, GCancellable *cancellable, G
|
||||||
if (want_help && command == NULL)
|
if (want_help && command == NULL)
|
||||||
{
|
{
|
||||||
static_delta_usage (argv, FALSE);
|
static_delta_usage (argv, FALSE);
|
||||||
ret = TRUE;
|
return TRUE; /* Note early return */
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!command->fn)
|
if (!command->fn)
|
||||||
{
|
{
|
||||||
g_autofree char *msg = g_strdup_printf ("Unknown command '%s'", cmdname);
|
|
||||||
static_delta_usage (argv, TRUE);
|
static_delta_usage (argv, TRUE);
|
||||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, msg);
|
return glnx_throw (error, "Unknown \"static-delta\" subcommand '%s'", cmdname);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!command->fn (argc, argv, cancellable, error))
|
g_autofree char *prgname = g_strdup_printf ("%s %s", g_get_prgname (), cmdname);
|
||||||
goto out;
|
g_set_prgname (prgname);
|
||||||
|
|
||||||
ret = TRUE;
|
return command->fn (argc, argv, cancellable, error);
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue