From ff9c308eee18da66f07700e5640627a6343d1392 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Mon, 14 Feb 2022 11:32:48 +0100 Subject: [PATCH] AppOptions: exit after -h or -v --- App/AppOptions.cpp | 18 +++++++----------- App/AppOptions.h | 2 -- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/App/AppOptions.cpp b/App/AppOptions.cpp index 85b8e00d796..baf0f4b9168 100644 --- a/App/AppOptions.cpp +++ b/App/AppOptions.cpp @@ -48,7 +48,8 @@ bool isValid(const QSize& win_size) ApplicationOptions::ApplicationOptions(int argc, char** argv) : m_options_is_consistent(false) { - m_options.add_options()("help,h", "print help message"); + m_options.add_options()("help,h", "print help message and exit"); + m_options.add_options()("version,v", "print version and exit"); m_options.add_options()("with-debug", "run application with debug printout"); m_options.add_options()(geometry, bpo::value<std::string>(), "Main window geometry, e.g. 1600x1000"); @@ -68,7 +69,7 @@ const bpo::variable_value& ApplicationOptions::operator[](const std::string& s) bool ApplicationOptions::find(std::string name) const { - return (m_variables_map.count(name)); + return m_variables_map.count(name); } bool ApplicationOptions::isConsistent() const @@ -117,14 +118,15 @@ boost::program_options::options_description& ApplicationOptions::getOptions() void ApplicationOptions::processOptions() { if (m_variables_map.count("help")) { - printHelpMessage(); - m_options_is_consistent = false; + std::cout << "BornAgain Graphical User Interface" << std::endl; + std::cout << m_options << std::endl; + exit(0); } else if (m_variables_map.count("version")) { std::cout << "BornAgain-" << GUI::Util::Path::getBornAgainVersionString().toStdString() << std::endl; - m_options_is_consistent = false; + exit(0); } else if (m_variables_map.count(geometry)) { @@ -135,12 +137,6 @@ void ApplicationOptions::processOptions() } } -void ApplicationOptions::printHelpMessage() const -{ - std::cout << "BornAgain Graphical User Interface" << std::endl; - std::cout << m_options << std::endl; -} - QSize ApplicationOptions::mainWindowSize() const { QString size_str = QString::fromStdString(m_variables_map[geometry].as<std::string>()); diff --git a/App/AppOptions.h b/App/AppOptions.h index ea5689a15dc..b55b7dd4c60 100644 --- a/App/AppOptions.h +++ b/App/AppOptions.h @@ -46,8 +46,6 @@ public: bool find(std::string name) const; private: - void printHelpMessage() const; - //! Parses command line arguments void parseCommandLine(int argc, char** argv); -- GitLab