13 #include "axom/CLI11.hpp"
22 std::unordered_map<std::string, std::string>
defineAndParse(
int argc,
char* argv[], std::string app_description)
29 axom::CLI::App app{app_description};
30 std::string input_file_path;
31 app.add_option(
"-i, --input-file", input_file_path,
"Input file to use")->check(axom::CLI::ExistingFile);
34 app.add_option(
"-c, --restart-cycle", restart_cycle,
"Cycle to restart from")->check(axom::CLI::PositiveNumber);
35 bool create_input_file_docs{
false};
36 app.add_flag(
"-d, --create-input-file-docs", create_input_file_docs,
37 "Writes Sphinx documentation for input file, then exits");
38 std::string output_directory;
39 app.add_option(
"-o, --output-directory", output_directory,
"Directory to put outputted files");
40 bool enable_paraview{
false};
41 app.add_flag(
"-p, --paraview", enable_paraview,
"Enable ParaView output");
42 bool print_unused{
false};
43 app.add_flag(
"-u, --print-unused", print_unused,
"Prints unused entries in input file, then exits");
45 app.add_flag(
"-v, --version",
version,
"Print version and provenance information, then exits");
49 app.parse(argc, argv);
50 }
catch (
const axom::CLI::ParseError& e) {
51 smith::logger::flush();
52 if (e.get_name() ==
"CallForHelp") {
53 auto msg = app.help();
57 auto err_msg = axom::CLI::FailureMessage::simple(&app, e);
58 SLIC_ERROR_ROOT(err_msg);
63 std::unordered_map<std::string, std::string> cli_opts;
66 cli_opts.insert({
"version", {}});
68 if (input_file_path.empty()) {
69 SLIC_ERROR_ROOT(
"No input file given. Use '--help' for command line options.");
72 cli_opts.insert({std::string(
"input-file"), input_file_path});
74 if (restart_opt->count() > 0) {
75 cli_opts[
"restart-cycle"] = std::to_string(restart_cycle);
77 if (create_input_file_docs) {
78 cli_opts.insert({
"create-input-file-docs", {}});
81 cli_opts.insert({
"print-unused", {}});
83 if (output_directory ==
"") {
87 cli_opts.insert({
"output-directory", output_directory});
88 if (enable_paraview) {
89 cli_opts.insert({
"paraview", {}});
90 cli_opts.insert({
"paraview-directory", output_directory +
"_paraview"});
99 std::string cliValueToString(std::string value) {
return value; }
101 std::string cliValueToString(
bool value) {
return value ?
"true" :
"false"; }
103 std::string cliValueToString(
int value) {
return std::to_string(value); }
107 void printGiven(std::unordered_map<std::string, std::string>& cli_opts)
110 std::string optsMsg = axom::fmt::format(
"\n{:*^80}\n",
"Command Line Options");
114 std::vector<std::pair<std::string, std::string>> opts_output_map{
115 {
"create-input-file-docs",
"Create Input File Docs"},
116 {
"input-file",
"Input File"},
117 {
"output-directory",
"Output Directory"},
118 {
"paraview",
"Enable ParaView output"},
119 {
"restart-cycle",
"Restart Cycle"},
120 {
"version",
"Print version"}};
124 for (
auto output_pair : opts_output_map) {
125 auto search = cli_opts.find(output_pair.first);
126 if (search != cli_opts.end()) {
127 optsMsg += axom::fmt::format(
"{0}: {1}\n", output_pair.second, detail::cliValueToString(search->second));
132 optsMsg += axom::fmt::format(
"{:*^80}\n",
"*");
134 SLIC_INFO_ROOT(optsMsg);
135 smith::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 Smith.