Include pull and other external commands in usage output
This commit is contained in:
parent
edf69d6283
commit
f5cf21e471
|
|
@ -30,7 +30,7 @@
|
||||||
#include "ot-main.h"
|
#include "ot-main.h"
|
||||||
#include "ot-builtins.h"
|
#include "ot-builtins.h"
|
||||||
|
|
||||||
static OstreeBuiltin builtins[] = {
|
static OstreeCommand commands[] = {
|
||||||
{ "cat", ostree_builtin_cat, 0 },
|
{ "cat", ostree_builtin_cat, 0 },
|
||||||
{ "config", ostree_builtin_config, 0 },
|
{ "config", ostree_builtin_config, 0 },
|
||||||
{ "checkout", ostree_builtin_checkout, 0 },
|
{ "checkout", ostree_builtin_checkout, 0 },
|
||||||
|
|
@ -44,6 +44,7 @@ static OstreeBuiltin builtins[] = {
|
||||||
{ "prune", ostree_builtin_prune, 0 },
|
{ "prune", ostree_builtin_prune, 0 },
|
||||||
{ "fsck", ostree_builtin_fsck, 0 },
|
{ "fsck", ostree_builtin_fsck, 0 },
|
||||||
{ "pack", ostree_builtin_pack, 0 },
|
{ "pack", ostree_builtin_pack, 0 },
|
||||||
|
{ "pull", NULL, 0 },
|
||||||
{ "remote", ostree_builtin_remote, 0 },
|
{ "remote", ostree_builtin_remote, 0 },
|
||||||
{ "rev-parse", ostree_builtin_rev_parse, 0 },
|
{ "rev-parse", ostree_builtin_rev_parse, 0 },
|
||||||
{ "remote", ostree_builtin_remote, 0 },
|
{ "remote", ostree_builtin_remote, 0 },
|
||||||
|
|
@ -94,7 +95,7 @@ main (int argc,
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = ostree_run (argc, argv, builtins, &error);
|
ret = ostree_run (argc, argv, commands, &error);
|
||||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
|
||||||
{
|
{
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
|
|
@ -102,7 +103,7 @@ main (int argc,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
|
||||||
ostree_usage (argv, builtins, TRUE);
|
ostree_usage (argv, commands, TRUE);
|
||||||
|
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1672,7 +1672,7 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static OstreeBuiltin builtins[] = {
|
static OstreeCommand commands[] = {
|
||||||
{ "pull", ostree_builtin_pull, 0 },
|
{ "pull", ostree_builtin_pull, 0 },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
@ -1681,5 +1681,5 @@ int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
return ostree_main (argc, argv, builtins);
|
return ostree_main (argc, argv, commands);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,11 @@
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
ostree_usage (char **argv, OstreeBuiltin *builtins, gboolean is_error)
|
ostree_usage (char **argv,
|
||||||
|
OstreeCommand *commands,
|
||||||
|
gboolean is_error)
|
||||||
{
|
{
|
||||||
OstreeBuiltin *builtin = builtins;
|
OstreeCommand *command = commands;
|
||||||
void (*print_func) (const gchar *format, ...);
|
void (*print_func) (const gchar *format, ...);
|
||||||
|
|
||||||
if (is_error)
|
if (is_error)
|
||||||
|
|
@ -44,10 +46,10 @@ ostree_usage (char **argv, OstreeBuiltin *builtins, gboolean is_error)
|
||||||
argv[0]);
|
argv[0]);
|
||||||
print_func ("Builtin commands:\n");
|
print_func ("Builtin commands:\n");
|
||||||
|
|
||||||
while (builtin->name)
|
while (command->name)
|
||||||
{
|
{
|
||||||
print_func (" %s\n", builtin->name);
|
print_func (" %s\n", command->name);
|
||||||
builtin++;
|
command++;
|
||||||
}
|
}
|
||||||
return (is_error ? 1 : 0);
|
return (is_error ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
@ -75,10 +77,10 @@ prep_builtin_argv (const char *builtin,
|
||||||
int
|
int
|
||||||
ostree_run (int argc,
|
ostree_run (int argc,
|
||||||
char **argv,
|
char **argv,
|
||||||
OstreeBuiltin *builtins,
|
OstreeCommand *commands,
|
||||||
GError **res_error)
|
GError **res_error)
|
||||||
{
|
{
|
||||||
OstreeBuiltin *builtin;
|
OstreeCommand *command;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
int cmd_argc;
|
int cmd_argc;
|
||||||
char **cmd_argv = NULL;
|
char **cmd_argv = NULL;
|
||||||
|
|
@ -99,7 +101,7 @@ ostree_run (int argc,
|
||||||
g_set_prgname (argv[0]);
|
g_set_prgname (argv[0]);
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
return ostree_usage (argv, builtins, 1);
|
return ostree_usage (argv, commands, TRUE);
|
||||||
|
|
||||||
am_root = getuid () == 0;
|
am_root = getuid () == 0;
|
||||||
have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
|
have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
|
||||||
|
|
@ -140,32 +142,32 @@ ostree_run (int argc,
|
||||||
cmd = argv[arg_off-1];
|
cmd = argv[arg_off-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
builtin = builtins;
|
command = commands;
|
||||||
while (builtin->name)
|
while (command->name)
|
||||||
{
|
{
|
||||||
if (g_strcmp0 (cmd, builtin->name) == 0)
|
if (g_strcmp0 (cmd, command->name) == 0)
|
||||||
break;
|
break;
|
||||||
builtin++;
|
command++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!builtin->name)
|
if (!command->fn)
|
||||||
{
|
{
|
||||||
ot_lfree char *msg = g_strdup_printf ("Unknown command '%s'", cmd);
|
ot_lfree char *msg = g_strdup_printf ("Unknown command '%s'", cmd);
|
||||||
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, msg);
|
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, msg);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repo == NULL && !(builtin->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
|
if (repo == NULL && !(command->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
|
||||||
{
|
{
|
||||||
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
"Command requires a --repo argument");
|
"Command requires a --repo argument");
|
||||||
ostree_usage (argv, builtins, TRUE);
|
ostree_usage (argv, commands, TRUE);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
prep_builtin_argv (cmd, argc-arg_off, argv+arg_off, &cmd_argc, &cmd_argv);
|
prep_builtin_argv (cmd, argc-arg_off, argv+arg_off, &cmd_argc, &cmd_argv);
|
||||||
|
|
||||||
if (!builtin->fn (cmd_argc, cmd_argv, repo_file, &error))
|
if (!command->fn (cmd_argc, cmd_argv, repo_file, &error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
@ -182,15 +184,15 @@ ostree_run (int argc,
|
||||||
int
|
int
|
||||||
ostree_main (int argc,
|
ostree_main (int argc,
|
||||||
char **argv,
|
char **argv,
|
||||||
OstreeBuiltin *builtins)
|
OstreeCommand *commands)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = ostree_run (argc, argv, builtins, &error);
|
ret = ostree_run (argc, argv, commands, &error);
|
||||||
|
|
||||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
|
||||||
ostree_usage (argv, builtins, TRUE);
|
ostree_usage (argv, commands, TRUE);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
gboolean (*fn) (int argc, char **argv, GFile *repo_path, GError **error);
|
gboolean (*fn) (int argc, char **argv, GFile *repo_path, GError **error);
|
||||||
int flags; /* OstreeBuiltinFlags */
|
int flags; /* OstreeBuiltinFlags */
|
||||||
} OstreeBuiltin;
|
} OstreeCommand;
|
||||||
|
|
||||||
int ostree_main (int argc, char **argv, OstreeBuiltin *builtins);
|
int ostree_main (int argc, char **argv, OstreeCommand *commands);
|
||||||
|
|
||||||
int ostree_run (int argc, char **argv, OstreeBuiltin *builtins, GError **error);
|
int ostree_run (int argc, char **argv, OstreeCommand *commands, GError **error);
|
||||||
|
|
||||||
int ostree_usage (char **argv, OstreeBuiltin *builtins, gboolean is_error);
|
int ostree_usage (char **argv, OstreeCommand *commands, gboolean is_error);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue