OGS
CommandLineArgumentParser.h File Reference

Detailed Description

Declaration of CommandLineArgumentParser.

Definition in file CommandLineArgumentParser.h.

#include <string>
#include <vector>
Include dependency graph for CommandLineArgumentParser.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CommandLineArguments
 

Functions

CommandLineArguments parseCommandLineArguments (int argc, char *argv[], bool const exit_on_exception=true)
 

Function Documentation

◆ parseCommandLineArguments()

CommandLineArguments parseCommandLineArguments ( int argc,
char * argv[],
bool const exit_on_exception = true )

Definition at line 21 of file CommandLineArgumentParser.cpp.

23{
24 // Parse CLI arguments.
25 TCLAP::CmdLine cmd(
26 "OpenGeoSys-6 software."
27 "\n"
28 "Copyright (c) 2012-2024, OpenGeoSys Community "
29 "(https://www.opengeosys.org) "
30 "\n"
31 "Distributed under a Modified BSD License. "
32 "See accompanying file LICENSE.txt or "
33 "https://www.opengeosys.org/project/license"
34 "\n"
35 "version: " +
37 "\n"
38 "CMake arguments: " +
39 CMakeInfoLib::CMakeInfo::cmake_args,
40 ' ',
42 "CMake arguments: " + CMakeInfoLib::CMakeInfo::cmake_args);
43
44 cmd.setExceptionHandling(exit_on_exception);
45
46 TCLAP::ValueArg<std::string> log_level_arg(
47 "l", "log-level",
48 "the verbosity of logging messages: none, error, warn, info, "
49 "debug, "
50 "all",
51 false,
52#ifdef NDEBUG
53 "info",
54#else
55 "all",
56#endif
57 "LOG_LEVEL");
58
59#ifndef _WIN32 // TODO: On windows floating point exceptions are not handled
60 // currently
61 TCLAP::SwitchArg enable_fpe_arg("", "enable-fpe",
62 "enables floating point exceptions");
63#endif // _WIN32
64 TCLAP::SwitchArg unbuffered_cout_arg("", "unbuffered-std-out",
65 "use unbuffered standard output");
66
67 TCLAP::ValueArg<std::string> reference_path_arg(
68 "r", "reference",
69 "Run output result comparison after successful simulation "
70 "comparing to all files in the given path. This requires test "
71 "definitions to be present in the project file.",
72 false, "", "PATH");
73
74 TCLAP::UnlabeledValueArg<std::string> project_arg(
75 "project-file",
76 "Path to the ogs6 project file.",
77 true,
78 "",
79 "PROJECT_FILE");
80
81 TCLAP::MultiArg<std::string> xml_patch_files_arg(
82 "p", "xml-patch",
83 "the xml patch file(s) which is (are) applied (in the given order) "
84 "to the PROJECT_FILE",
85 false, "");
86
87 TCLAP::ValueArg<std::string> outdir_arg("o", "output-directory",
88 "the output directory to write to",
89 false, "", "PATH");
90
91 TCLAP::ValueArg<std::string> mesh_dir_arg(
92 "m", "mesh-input-directory",
93 "the directory where the meshes are read from", false, "", "PATH");
94
95 TCLAP::ValueArg<std::string> script_dir_arg(
96 "s", "script-input-directory",
97 "the directory where script files (e.g. Python BCs) are read from",
98 false, "", "PATH");
99
100 TCLAP::SwitchArg write_prj_arg("",
101 "write-prj",
102 "Writes processed project file to output "
103 "path / [prj_base_name]_processed.prj.");
104
105 TCLAP::SwitchArg nonfatal_arg("",
106 "config-warnings-nonfatal",
107 "warnings from parsing the configuration "
108 "file will not trigger program abortion");
109 cmd.add(reference_path_arg);
110 cmd.add(project_arg);
111 cmd.add(xml_patch_files_arg);
112 cmd.add(outdir_arg);
113 cmd.add(mesh_dir_arg);
114 cmd.add(script_dir_arg);
115 cmd.add(write_prj_arg);
116 cmd.add(log_level_arg);
117 cmd.add(nonfatal_arg);
118 cmd.add(unbuffered_cout_arg);
119#ifndef _WIN32 // TODO: On windows floating point exceptions are not handled
120 // currently
121 cmd.add(enable_fpe_arg);
122#endif // _WIN32
123
124 cmd.parse(argc, argv);
125
126 CommandLineArguments cli_args;
127 cli_args.reference_path = reference_path_arg.getValue();
128 cli_args.reference_path_is_set = reference_path_arg.isSet();
129 cli_args.project = project_arg.getValue();
130
132
133 cli_args.xml_patch_file_names = xml_patch_files_arg.getValue();
134 cli_args.outdir = outdir_arg.getValue();
135 cli_args.mesh_dir = mesh_dir_arg.getValue().empty()
137 : mesh_dir_arg.getValue();
138 cli_args.script_dir = script_dir_arg.getValue().empty()
140 : script_dir_arg.getValue();
141 cli_args.nonfatal = nonfatal_arg.getValue();
142 cli_args.log_level = log_level_arg.getValue();
143 cli_args.write_prj = write_prj_arg.getValue();
144
145 // deactivate buffer for standard output if specified
146 if (unbuffered_cout_arg.isSet())
147 {
148 std::cout.setf(std::ios::unitbuf);
149 }
150#ifndef _WIN32
151 cli_args.enable_fpe_is_set = enable_fpe_arg.isSet();
152#endif // _WIN32
153
154 return cli_args;
155}
std::string getValue(std::string const &line, std::string const &val_name, bool is_string)
std::string const & getProjectDirectory()
Returns the directory where the prj file resides.
std::string extractPath(std::string const &pathname)
void setProjectDirectory(std::string const &dir)
Sets the project directory.
GITINFOLIB_EXPORT const std::string ogs_version
std::vector< std::string > xml_patch_file_names

References CommandLineArguments::enable_fpe_is_set, BaseLib::extractPath(), BaseLib::getProjectDirectory(), CommandLineArguments::log_level, CommandLineArguments::mesh_dir, CommandLineArguments::nonfatal, GitInfoLib::GitInfo::ogs_version, CommandLineArguments::outdir, CommandLineArguments::project, CommandLineArguments::reference_path, CommandLineArguments::reference_path_is_set, CommandLineArguments::script_dir, BaseLib::setProjectDirectory(), CommandLineArguments::write_prj, and CommandLineArguments::xml_patch_file_names.

Referenced by initOGS(), and main().