main: Report unknown command before unknown arg

This fixes: https://github.com/flatpak/flatpak/issues/23
This commit is contained in:
Alexander Larsson
2016-05-26 19:48:25 +02:00
parent 22adaa3c8c
commit 9ec3e7346b

View File

@@ -280,27 +280,29 @@ flatpak_run (int argc,
if (!command->fn)
{
GOptionContext *context;
g_autoptr(GOptionContext) context = NULL;
g_autofree char *help;
context = flatpak_option_context_new_with_commands (commands);
/* This will not return for some options (e.g. --version). */
if (flatpak_option_context_parse (context, NULL, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, &error))
if (command_name != NULL)
{
if (command_name == NULL)
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
"No command specified");
else
g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Unknown command '%s'", command_name);
g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Unknown command '%s'", command_name);
}
else
{
/* This will not return for some options (e.g. --version). */
if (flatpak_option_context_parse (context, NULL, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, &error))
{
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
"No command specified");
}
}
help = g_option_context_get_help (context, FALSE, NULL);
g_printerr ("%s", help);
g_option_context_free (context);
goto out;
}