From 9ec3e7346bb6f2aabfeae1d25dabb4bdecb2be4d Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 26 May 2016 19:48:25 +0200 Subject: [PATCH] main: Report unknown command before unknown arg This fixes: https://github.com/flatpak/flatpak/issues/23 --- app/flatpak-main.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/flatpak-main.c b/app/flatpak-main.c index 272f0f6c..c37f8e3e 100644 --- a/app/flatpak-main.c +++ b/app/flatpak-main.c @@ -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; }