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