43 std::optional<std::string>
value;
83 void addArguments(
const std::vector<std::string> & args);
117 std::unique_ptr<CommandLine>
119 const std::string & subapp_name,
120 const std::vector<std::string> & input_cli_args);
191 std::string
formatEntry(
const Entry & entry)
const;
210 template <
typename T>
212 const CommandLineParam & param,
213 const std::string & cli_switch,
238 template <
typename T>
242 const std::string & cli_switch,
245 auto & entry = *entry_it;
252 if constexpr (std::is_same_v<bool, T>)
259 "' is a boolean and does not support a value but the value '",
261 "' was provided.\nDoc string: ",
272 const auto set_value = [&cli_switch](
const std::string & from,
auto &
value)
274 using type =
typename std::remove_reference<decltype(value)>::type;
283 if constexpr (std::is_same_v<type, std::string> || std::is_same_v<type, MooseEnum>)
286 value = MooseUtils::convert<type>(from,
true);
288 catch (std::exception & e)
291 mooseError(
"While parsing command line option '",
312 auto next_entry_it = std::next(entry_it);
313 if (next_entry_it !=
_entries.end())
315 const auto & next_entry = *next_entry_it;
316 if (!next_entry.used &&
317 (required || !next_entry.hit_param) &&
320 next_entry.value_separator &&
321 *next_entry.value_separator ==
"=" &&
324 const auto & next_entry = *next_entry_it;
326 entry.value = next_entry.name + *next_entry.value_separator + *next_entry.value;
327 entry.raw_args.insert(
328 entry.raw_args.end(), next_entry.raw_args.begin(), next_entry.raw_args.end());
338 if constexpr (std::is_same_v<T, std::vector<std::string>>)
340 std::vector<std::string> split_values;
342 value.resize(split_values.size());
344 set_value(split_values[i],
value[i]);
348 set_value(*entry.value,
value);
354 "' requires a value and one was not provided.\nDoc string: ",
bool _has_parsed
Whether or not the Parser has parsed yet.
std::string getExecutableName() const
std::optional< std::string > value_separator
The string that separates the value, if a value exists (space or =)
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
bool beginsWith(const std::string &value, const std::string &begin_value)
std::list< Entry >::const_iterator findCommandLineParam(const std::string &name) const
std::string formatEntry(const Entry &entry) const
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Stores name/value pairs for each command line argument.
void printUsage() const
Print the usage info for this command line.
std::string name
The name, i.e, ["-foo=bar"] -> "-foo" or ["--foo", "bar"] -> "--foo".
void setCommandLineParam(std::list< Entry >::iterator entry_it, const CommandLineParam ¶m, const std::string &cli_switch, T &value)
Sets an InputParameters command line option at value.
void addArgument(const std::string &arg)
Adds a single argument.
This class wraps provides and tracks access to command line parameters.
std::list< Entry > _entries
The parsed command line entries (arguments split into name value pairs) This is a list because it is ...
std::vector< std::string > raw_args
The raw arguments that represent these split values.
bool _command_line_params_populated
Whether or not command line parameters have been populated.
void populateCommandLineParams(InputParameters ¶ms)
Populates the command line input parameters from params.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Stores information pertaining to a command line InputParameter.
std::map< std::string, CommandLineParam > _command_line_params
The command line parameters, added by populateCommandLineParams()
std::vector< std::string > _argv
Storage for the raw argv.
const std::list< Entry > & getEntries() const
std::string description
The description (doc string) for the parameter.
bool hasArgument(const std::string &arg) const
InputParameters::CommandLineMetadata metadata
The command line metadata for the parameter.
bool used
Whether or not this set of arguments was used.
void removeArgument(const std::string &arg)
Removes an argument that must exist.
bool hit_param
Whether or not this parameter is recognized as a HIT parameter.
std::optional< std::string > subapp_name
The name of the subapp, if any (with subapp:something=value syntax)
void parse()
Performs the parsing, which is the combining of arguments into [name, value] pairs.
std::unique_ptr< CommandLine > initSubAppCommandLine(const std::string &multiapp_name, const std::string &subapp_name, const std::vector< std::string > &input_cli_args)
Initializes a new CommandLine for a subapp with a MultiApp named multiapp_name and a subapp named sub...
bool global
Whether or not this parameter is global (passed to MultiApps)
std::vector< std::string > unusedHitParams(const Parallel::Communicator &comm) const
Returns the HIT command line arguments that are not used.
bool _throw_on_error
Variable to turn on exceptions during mooseError(), should only be used within MOOSE unit tests or wh...
std::optional< std::string > value
The value, i.e. ["-foo=bar"] -> "bar" or ["-foo"] -> empty, if any.
auto index_range(const T &sizable)
const std::vector< std::string > & getArguments()
std::string getExecutableNameBase() const
void addArguments(int argc, char *argv[])
Adds arguments from raw argc and argv.
std::string buildHitParams()