From: Gunnar Beutner Date: Sat, 2 Feb 2013 22:29:02 +0000 (+0100) Subject: Gracefully deal with unknown command-line options. X-Git-Tag: v0.0.2~572 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3a73dde1e7d89a830f6d4ff66931f625098403e;p=icinga2 Gracefully deal with unknown command-line options. --- diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 2b3ae47c7..b2d66235b 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -88,7 +88,16 @@ int main(int argc, char **argv) ; po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); + + try { + po::store(po::parse_command_line(argc, argv, desc), vm); + } catch (const po::unknown_option& ex) { + stringstream msgbuf; + msgbuf << "Error while parsing command-line options: " << ex.what(); + Logger::Write(LogCritical, "icinga-app", msgbuf.str()); + return EXIT_FAILURE; + } + po::notify(vm); if (vm.count("debug")) @@ -96,7 +105,6 @@ int main(int argc, char **argv) if (vm.count("help")) { std::cout << desc << "\n"; - return EXIT_SUCCESS; }