From 1c950d59bb56349f7402a9d57eab90e350dc21e4 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de>
Date: Wed, 7 Jun 2023 14:06:36 +0000
Subject: [PATCH] algo::Options: Print help message on unknown option.

---
 algo/base/Options.cxx | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/algo/base/Options.cxx b/algo/base/Options.cxx
index 4ac19dc780..36e2c1eda8 100644
--- a/algo/base/Options.cxx
+++ b/algo/base/Options.cxx
@@ -73,11 +73,19 @@ Options::Options(int argc, char** argv)
   po::variables_map vm;
   po::command_line_parser parser {argc, argv};
   parser.options(cmdline_options);
-  po::store(parser.run(), vm);
+  try {
+    auto result = parser.run();
+    po::store(result, vm);
+  }
+  catch (const boost::wrapexcept<po::unknown_option>& e) {
+    std::cerr << "Error: " << e.what() << std::endl;
+    std::cerr << cmdline_options << std::endl;
+    std::exit(EXIT_FAILURE);
+  }
 
   if (vm.count("help")) {
     std::cerr << cmdline_options << std::endl;
-    std::exit(0);
+    std::exit(EXIT_SUCCESS);
   }
 
   try {
@@ -86,6 +94,6 @@ Options::Options(int argc, char** argv)
   catch (const po::required_option& e) {
     std::cerr << "Error: " << e.what() << std::endl;
     std::cerr << cmdline_options << std::endl;
-    std::exit(1);
+    std::exit(EXIT_FAILURE);
   }
 }
-- 
GitLab