9 #include "axom/CLI11.hpp"
19 std::unordered_map<std::string, std::string>
defineAndParse(
int argc,
char* argv[], std::string app_description)
26 axom::CLI::App app{app_description};
27 std::string input_file_path;
28 app.add_option(
"-i, --input-file", input_file_path,
"Input file to use")->check(axom::CLI::ExistingFile);
31 app.add_option(
"-c, --restart-cycle", restart_cycle,
"Cycle to restart from")->check(axom::CLI::PositiveNumber);
32 bool create_input_file_docs{
false};
33 app.add_flag(
"-d, --create-input-file-docs", create_input_file_docs,
34 "Writes Sphinx documentation for input file, then exits");
35 std::string output_directory;
36 app.add_option(
"-o, --output-directory", output_directory,
"Directory to put outputted files");
37 bool enable_paraview{
false};
38 app.add_flag(
"-p, --paraview", enable_paraview,
"Enable ParaView output");
39 bool print_unused{
false};
40 app.add_flag(
"-u, --print-unused", print_unused,
"Prints unused entries in input file, then exits");
42 app.add_flag(
"-v, --version",
version,
"Print version and provenance information, then exits");
46 app.parse(argc, argv);
47 }
catch (
const axom::CLI::ParseError& e) {
48 serac::logger::flush();
49 if (e.get_name() ==
"CallForHelp") {
50 auto msg = app.help();
54 auto err_msg = axom::CLI::FailureMessage::simple(&app, e);
55 SLIC_ERROR_ROOT(err_msg);
60 std::unordered_map<std::string, std::string> cli_opts;
63 cli_opts.insert({
"version", {}});
65 if (input_file_path.empty()) {
66 SLIC_ERROR_ROOT(
"No input file given. Use '--help' for command line options.");
69 cli_opts.insert({std::string(
"input-file"), input_file_path});
71 if (restart_opt->count() > 0) {
72 cli_opts[
"restart-cycle"] = std::to_string(restart_cycle);
74 if (create_input_file_docs) {
75 cli_opts.insert({
"create-input-file-docs", {}});
78 cli_opts.insert({
"print-unused", {}});
80 if (output_directory ==
"") {
84 cli_opts.insert({
"output-directory", output_directory});
85 if (enable_paraview) {
86 cli_opts.insert({
"paraview", {}});
87 cli_opts.insert({
"paraview-directory", output_directory +
"_paraview"});
96 std::string cliValueToString(std::string value) {
return value; }
98 std::string cliValueToString(
bool value) {
return value ?
"true" :
"false"; }
100 std::string cliValueToString(
int value) {
return std::to_string(value); }
104 void printGiven(std::unordered_map<std::string, std::string>& cli_opts)
107 std::string optsMsg = axom::fmt::format(
"\n{:*^80}\n",
"Command Line Options");
111 std::vector<std::pair<std::string, std::string>> opts_output_map{
112 {
"create-input-file-docs",
"Create Input File Docs"},
113 {
"input-file",
"Input File"},
114 {
"output-directory",
"Output Directory"},
115 {
"paraview",
"Enable ParaView output"},
116 {
"restart-cycle",
"Restart Cycle"},
117 {
"version",
"Print version"}};
121 for (
auto output_pair : opts_output_map) {
122 auto search = cli_opts.find(output_pair.first);
123 if (search != cli_opts.end()) {
124 optsMsg += axom::fmt::format(
"{0}: {1}\n", output_pair.second, detail::cliValueToString(search->second));
129 optsMsg += axom::fmt::format(
"{:*^80}\n",
"*");
131 SLIC_INFO_ROOT(optsMsg);
132 serac::logger::flush();
This file contains the all the necessary functions and macros required for interacting with the comma...
This file contains the all the necessary functions and macros required for logging as well as a helpe...
Command line functionality.
std::unordered_map< std::string, std::string > defineAndParse(int argc, char *argv[], std::string app_description)
Defines command line options and parses the found values.
void printGiven(std::unordered_map< std::string, std::string > &cli_opts)
Prints all given command line options to the screen.
std::string version(bool add_SHA)
Returns a string for the version of Serac.
void exitGracefully(bool error)
Exits the program gracefully after cleaning up necessary tasks.
Helper functions for exiting Serac cleanly.