[icinga-checkins] icinga.org: icinga2/master: Gracefully deal with unknown command-line options.

git at icinga.org git at icinga.org
Sat Feb 2 23:29:13 CET 2013


Module: icinga2
Branch: master
Commit: c3a73dde1e7d89a830f6d4ff66931f625098403e
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=c3a73dde1e7d89a830f6d4ff66931f625098403e

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sat Feb  2 23:29:02 2013 +0100

Gracefully deal with unknown command-line options.

---

 icinga-app/icinga.cpp |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp
index 2b3ae47..b2d6623 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;
 	}
 





More information about the icinga-checkins mailing list