Merge pull request #7162 from Icinga/bugfix/cli-no-command-status-code

CLI: Return non-zero on unknown sub commands
This commit is contained in:
Michael Friedrich 2019-05-07 13:23:05 +02:00 committed by GitHub
commit 11dc30407c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View 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();

View 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);