Skip to content

CLI: Return non-zero on unknown sub commands #7162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions icinga-app/icinga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion lib/cli/clicommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,12 @@ bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& vi
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);
Expand Down