OGS
CommandLineArgumentParser.h File Reference
#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 14 of file CommandLineArgumentParser.cpp.

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

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

Referenced by OGSSimulation::OGSSimulation(), checkCommandLineArguments(), and main().