diff --git a/Applications/CLI/CMakeLists.txt b/Applications/CLI/CMakeLists.txt index 204f38cab4108a0fd9e1a52d807e6f2874b11ccb..944221b15013df3b922fec0230d9516c0df8b926 100644 --- a/Applications/CLI/CMakeLists.txt +++ b/Applications/CLI/CMakeLists.txt @@ -47,7 +47,7 @@ if(OGS_USE_PYTHON) ) endif() -ogs_add_executable(ogs ogs.cpp) +ogs_add_executable(ogs ogs.cpp CommandLineArgumentParser.cpp) target_link_libraries( ogs diff --git a/Applications/CLI/CommandLineArgumentParser.cpp b/Applications/CLI/CommandLineArgumentParser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..de33354834cb6b71c62860dbf10c2fb58b745f95 --- /dev/null +++ b/Applications/CLI/CommandLineArgumentParser.cpp @@ -0,0 +1,116 @@ +/** + * \brief Implementation of CommandLineArgumentParser. + * \file + * + * \copyright + * Copyright (c) 2012-2022, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#include <tclap/CmdLine.h> + +#include "CommandLineArgumentParser.h" + +#include "InfoLib/CMakeInfo.h" +#include "InfoLib/GitInfo.h" + +CommandLineArgumentParser::CommandLineArgumentParser(int argc, char* argv[]) +{ + // Parse CLI arguments. + TCLAP::CmdLine cmd( + "OpenGeoSys-6 software.\n" + "Copyright (c) 2012-2022, OpenGeoSys Community " + "(http://www.opengeosys.org) " + "Distributed under a Modified BSD License. " + "See accompanying file LICENSE.txt or " + "http://www.opengeosys.org/project/license\n" + "version: " + + GitInfoLib::GitInfo::ogs_version + "\n" + + "CMake arguments: " + CMakeInfoLib::CMakeInfo::cmake_args, + ' ', + GitInfoLib::GitInfo::ogs_version + "\n\n" + + "CMake arguments: " + CMakeInfoLib::CMakeInfo::cmake_args); + + TCLAP::ValueArg<std::string> log_level_arg( + "l", "log-level", + "the verbosity of logging messages: none, error, warn, info, " + "debug, " + "all", + false, +#ifdef NDEBUG + "info", +#else + "all", +#endif + "LOG_LEVEL"); + +#ifndef _WIN32 // TODO: On windows floating point exceptions are not handled + // currently + TCLAP::SwitchArg enable_fpe_arg("", "enable-fpe", + "enables floating point exceptions"); +#endif // _WIN32 + TCLAP::SwitchArg unbuffered_cout_arg("", "unbuffered-std-out", + "use unbuffered standard output"); + + TCLAP::ValueArg<std::string> reference_path_arg( + "r", "reference", + "Run output result comparison after successful simulation " + "comparing to all files in the given path. This requires test " + "definitions to be present in the project file.", + false, "", "PATH"); + + TCLAP::UnlabeledValueArg<std::string> project_arg( + "project-file", + "Path to the ogs6 project file.", + true, + "", + "PROJECT_FILE"); + + TCLAP::MultiArg<std::string> xml_patch_files_arg( + "p", "xml-patch", + "the xml patch file(s) which is (are) applied (in the given order) " + "to the PROJECT_FILE", + false, ""); + + TCLAP::ValueArg<std::string> outdir_arg("o", "output-directory", + "the output directory to write to", + false, "", "PATH"); + + TCLAP::SwitchArg nonfatal_arg("", + "config-warnings-nonfatal", + "warnings from parsing the configuration " + "file will not trigger program abortion"); + cmd.add(reference_path_arg); + cmd.add(project_arg); + cmd.add(xml_patch_files_arg); + cmd.add(outdir_arg); + cmd.add(log_level_arg); + cmd.add(nonfatal_arg); + cmd.add(unbuffered_cout_arg); +#ifndef _WIN32 // TODO: On windows floating point exceptions are not handled + // currently + cmd.add(enable_fpe_arg); +#endif // _WIN32 + + cmd.parse(argc, argv); + + reference_path = reference_path_arg.getValue(); + reference_path_is_set = reference_path_arg.isSet(); + project = project_arg.getValue(); + xml_patch_file_names = xml_patch_files_arg.getValue(); + outdir = outdir_arg.getValue(); + nonfatal = nonfatal_arg.getValue(); + log_level = log_level_arg.getValue(); + + // deactivate buffer for standard output if specified + if (unbuffered_cout_arg.isSet()) + { + std::cout.setf(std::ios::unitbuf); + } +#ifndef _WIN32 + enable_fpe_is_set = enable_fpe_arg.isSet(); +#endif // _WIN32 +} diff --git a/Applications/CLI/CommandLineArgumentParser.h b/Applications/CLI/CommandLineArgumentParser.h index c16d9b05d92b64bf7740447f53a70cfa1411fd68..a6fbe716afc649aadcfab5c698325a16317474e2 100644 --- a/Applications/CLI/CommandLineArgumentParser.h +++ b/Applications/CLI/CommandLineArgumentParser.h @@ -1,5 +1,6 @@ /** - * \brief Declaration / Implementation of CommandLineArgumentParser. + * \brief Declaration of CommandLineArgumentParser. + * \file * * \copyright * Copyright (c) 2012-2022, OpenGeoSys Community (http://www.opengeosys.org) @@ -9,115 +10,14 @@ * */ -#include <tclap/CmdLine.h> - #include <string> #include <vector> -#include "InfoLib/CMakeInfo.h" -#include "InfoLib/GitInfo.h" - #pragma once struct CommandLineArgumentParser final { - CommandLineArgumentParser(int argc, char* argv[]) - { - // Parse CLI arguments. - TCLAP::CmdLine cmd( - "OpenGeoSys-6 software.\n" - "Copyright (c) 2012-2022, OpenGeoSys Community " - "(http://www.opengeosys.org) " - "Distributed under a Modified BSD License. " - "See accompanying file LICENSE.txt or " - "http://www.opengeosys.org/project/license\n" - "version: " + - GitInfoLib::GitInfo::ogs_version + "\n" + - "CMake arguments: " + CMakeInfoLib::CMakeInfo::cmake_args, - ' ', - GitInfoLib::GitInfo::ogs_version + "\n\n" + - "CMake arguments: " + CMakeInfoLib::CMakeInfo::cmake_args); - - TCLAP::ValueArg<std::string> log_level_arg( - "l", "log-level", - "the verbosity of logging messages: none, error, warn, info, " - "debug, " - "all", - false, -#ifdef NDEBUG - "info", -#else - "all", -#endif - "LOG_LEVEL"); - -#ifndef _WIN32 // TODO: On windows floating point exceptions are not handled - // currently - TCLAP::SwitchArg enable_fpe_arg("", "enable-fpe", - "enables floating point exceptions"); -#endif // _WIN32 - TCLAP::SwitchArg unbuffered_cout_arg("", "unbuffered-std-out", - "use unbuffered standard output"); - - TCLAP::ValueArg<std::string> reference_path_arg( - "r", "reference", - "Run output result comparison after successful simulation " - "comparing to all files in the given path. This requires test " - "definitions to be present in the project file.", - false, "", "PATH"); - - TCLAP::UnlabeledValueArg<std::string> project_arg( - "project-file", - "Path to the ogs6 project file.", - true, - "", - "PROJECT_FILE"); - - TCLAP::MultiArg<std::string> xml_patch_files_arg( - "p", "xml-patch", - "the xml patch file(s) which is (are) applied (in the given order) " - "to the PROJECT_FILE", - false, ""); - - TCLAP::ValueArg<std::string> outdir_arg( - "o", "output-directory", "the output directory to write to", false, - "", "PATH"); - - TCLAP::SwitchArg nonfatal_arg("", - "config-warnings-nonfatal", - "warnings from parsing the configuration " - "file will not trigger program abortion"); - cmd.add(reference_path_arg); - cmd.add(project_arg); - cmd.add(xml_patch_files_arg); - cmd.add(outdir_arg); - cmd.add(log_level_arg); - cmd.add(nonfatal_arg); - cmd.add(unbuffered_cout_arg); -#ifndef _WIN32 // TODO: On windows floating point exceptions are not handled - // currently - cmd.add(enable_fpe_arg); -#endif // _WIN32 - - cmd.parse(argc, argv); - - reference_path = reference_path_arg.getValue(); - reference_path_is_set = reference_path_arg.isSet(); - project = project_arg.getValue(); - xml_patch_file_names = xml_patch_files_arg.getValue(); - outdir = outdir_arg.getValue(); - nonfatal = nonfatal_arg.getValue(); - log_level = log_level_arg.getValue(); - - // deactivate buffer for standard output if specified - if (unbuffered_cout_arg.isSet()) - { - std::cout.setf(std::ios::unitbuf); - } -#ifndef _WIN32 - enable_fpe_is_set = enable_fpe_arg.isSet(); -#endif // _WIN32 - } + CommandLineArgumentParser(int argc, char* argv[]); std::string reference_path; std::string project;