main: Only parse options in subcommands
This makes e.g. "ostree commit --help" work, which is really good.
This commit is contained in:
parent
be2bebaf3e
commit
b7460cf0b6
|
|
@ -29,13 +29,6 @@
|
||||||
#include "ot-main.h"
|
#include "ot-main.h"
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
|
|
||||||
static gboolean opt_version;
|
|
||||||
|
|
||||||
static GOptionEntry main_options[] = {
|
|
||||||
{ "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Display version", NULL },
|
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
int
|
||||||
ostree_usage (char **argv,
|
ostree_usage (char **argv,
|
||||||
OstreeCommand *commands,
|
OstreeCommand *commands,
|
||||||
|
|
@ -87,14 +80,11 @@ ostree_run (int argc,
|
||||||
OstreeCommand *commands,
|
OstreeCommand *commands,
|
||||||
GError **res_error)
|
GError **res_error)
|
||||||
{
|
{
|
||||||
GOptionContext *optcontext;
|
|
||||||
OstreeCommand *command;
|
OstreeCommand *command;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
int cmd_argc;
|
int cmd_argc;
|
||||||
char **cmd_argv = NULL;
|
char **cmd_argv = NULL;
|
||||||
gboolean have_repo_arg;
|
gboolean have_repo_arg;
|
||||||
const char *binname = NULL;
|
|
||||||
const char *slash = NULL;
|
|
||||||
const char *cmd = NULL;
|
const char *cmd = NULL;
|
||||||
const char *repo = NULL;
|
const char *repo = NULL;
|
||||||
const char *host_repo_path = "/ostree/repo";
|
const char *host_repo_path = "/ostree/repo";
|
||||||
|
|
@ -111,14 +101,7 @@ ostree_run (int argc,
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
return ostree_usage (argv, commands, TRUE);
|
return ostree_usage (argv, commands, TRUE);
|
||||||
|
|
||||||
optcontext = g_option_context_new ("COMMAND [OPTIONS...]");
|
if (g_str_has_prefix (argv[1], "--version"))
|
||||||
g_option_context_add_main_entries (optcontext, main_options, NULL);
|
|
||||||
g_option_context_set_ignore_unknown_options (optcontext, TRUE);
|
|
||||||
|
|
||||||
if (!g_option_context_parse (optcontext, &argc, &argv, &error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (opt_version)
|
|
||||||
{
|
{
|
||||||
g_print ("%s\n %s\n", PACKAGE_STRING, OSTREE_FEATURES);
|
g_print ("%s\n %s\n", PACKAGE_STRING, OSTREE_FEATURES);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -134,25 +117,7 @@ ostree_run (int argc,
|
||||||
if (repo)
|
if (repo)
|
||||||
repo_file = g_file_new_for_path (repo);
|
repo_file = g_file_new_for_path (repo);
|
||||||
|
|
||||||
slash = strrchr (argv[0], '/');
|
if (!have_repo_arg)
|
||||||
if (slash)
|
|
||||||
binname = slash+1;
|
|
||||||
else
|
|
||||||
binname = argv[0];
|
|
||||||
|
|
||||||
if (g_str_has_prefix (binname, "lt-"))
|
|
||||||
binname += 3;
|
|
||||||
|
|
||||||
if (g_str_has_prefix (binname, "ostree-"))
|
|
||||||
{
|
|
||||||
cmd = strchr (binname, '-');
|
|
||||||
g_assert (cmd);
|
|
||||||
cmd += 1;
|
|
||||||
arg_off = 1;
|
|
||||||
if (have_repo_arg)
|
|
||||||
arg_off += 1;
|
|
||||||
}
|
|
||||||
else if (!have_repo_arg)
|
|
||||||
{
|
{
|
||||||
arg_off = 2;
|
arg_off = 2;
|
||||||
cmd = argv[arg_off-1];
|
cmd = argv[arg_off-1];
|
||||||
|
|
@ -178,6 +143,8 @@ ostree_run (int argc,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_set_prgname (g_strdup_printf ("ostree %s", cmd));
|
||||||
|
|
||||||
if (repo == NULL && !(command->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,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue