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