]> granicus.if.org Git - icinga2/commitdiff
CLI: Return non-zero on unknown sub commands 7162/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Tue, 7 May 2019 10:43:53 +0000 (12:43 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 7 May 2019 10:43:53 +0000 (12:43 +0200)
fixes #6585

icinga-app/icinga.cpp
lib/cli/clicommand.cpp

index 5d3e3165e4091b46d84317143b7cb3b65d03e59b..ca103f3146a303058b1d0595527ada76bb4dc904 100644 (file)
@@ -327,8 +327,13 @@ static int Main()
        po::variables_map vm;
 
        try {
-               CLICommand::ParseCommand(argc, argv, visibleDesc, hiddenDesc, positionalDesc,
-                       vm, cmdname, command, autocomplete);
+               if (!CLICommand::ParseCommand(argc, argv, visibleDesc, hiddenDesc, positionalDesc,
+                       vm, cmdname, command, autocomplete)) {
+
+                       Log(LogCritical, "icinga-app")
+                               << "Command parsing error. Try '--help'.";
+                       return EXIT_FAILURE;
+               }
        } catch (const std::exception& ex) {
                Log(LogCritical, "icinga-app")
                        << "Error while parsing command-line options: " << ex.what();
index 878beac77a2b629f041edab8626e6601c8e00966..7e93c5c61549fbb6923afec49686b396a1bc2aba 100644 (file)
@@ -200,9 +200,12 @@ found_command:
                visibleDesc.add(vdesc);
        }
 
-       if (autocomplete || (tried_command && !command))
+       if (autocomplete)
                return true;
 
+       if (tried_command && !command)
+               return false;
+
        po::options_description adesc;
        adesc.add(visibleDesc);
        adesc.add(hiddenDesc);