From a2e70955e101254b5ef225f9cad1bea8b287e682 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 4 Sep 2016 17:01:46 +0200 Subject: [PATCH] Fix command line parser for "icinga2 --version" fixes #12632 --- lib/cli/clicommand.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/cli/clicommand.cpp b/lib/cli/clicommand.cpp index 714729220..74d129c77 100644 --- a/lib/cli/clicommand.cpp +++ b/lib/cli/clicommand.cpp @@ -171,6 +171,7 @@ bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& vi std::vector best_match; int arg_end = 0; + bool tried_command = false; for (const CLIKeyValue& kv : GetRegistry()) { const std::vector& vname = kv.first; @@ -178,11 +179,13 @@ bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& vi std::vector::size_type i; int k; for (i = 0, k = 1; i < vname.size() && k < argc; i++, k++) { - if (strcmp(argv[k], "--no-stack-rlimit") == 0 || strcmp(argv[k], "--autocomplete") == 0 || strcmp(argv[k], "--scm") == 0) { + if (strncmp(argv[k], "--", 2) == 0) { i--; continue; } + tried_command = true; + if (vname[i] != argv[k]) break; @@ -207,7 +210,7 @@ found_command: visibleDesc.add(vdesc); } - if (autocomplete || !command) + if (autocomplete || (tried_command && !command)) return true; po::options_description adesc;