Skip to content

Commit 11dc304

Browse files
author
Michael Friedrich
authored
Merge pull request #7162 from Icinga/bugfix/cli-no-command-status-code
CLI: Return non-zero on unknown sub commands
2 parents aa88271 + 00bc0b2 commit 11dc304

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

icinga-app/icinga.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,13 @@ static int Main()
327327
po::variables_map vm;
328328

329329
try {
330-
CLICommand::ParseCommand(argc, argv, visibleDesc, hiddenDesc, positionalDesc,
331-
vm, cmdname, command, autocomplete);
330+
if (!CLICommand::ParseCommand(argc, argv, visibleDesc, hiddenDesc, positionalDesc,
331+
vm, cmdname, command, autocomplete)) {
332+
333+
Log(LogCritical, "icinga-app")
334+
<< "Command parsing error. Try '--help'.";
335+
return EXIT_FAILURE;
336+
}
332337
} catch (const std::exception& ex) {
333338
Log(LogCritical, "icinga-app")
334339
<< "Error while parsing command-line options: " << ex.what();

lib/cli/clicommand.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& vi
200200
visibleDesc.add(vdesc);
201201
}
202202

203-
if (autocomplete || (tried_command && !command))
203+
if (autocomplete)
204204
return true;
205205

206+
if (tried_command && !command)
207+
return false;
208+
206209
po::options_description adesc;
207210
adesc.add(visibleDesc);
208211
adesc.add(hiddenDesc);

0 commit comments

Comments
 (0)