43 std::optional<std::string>
value;
83 void addArguments(
const std::vector<std::string> & args);
122 std::unique_ptr<CommandLine>
124 const std::string & subapp_name,
125 const std::vector<std::string> & input_cli_args,
126 const std::set<std::string> & exclude_params = {});
197 std::string
formatEntry(
const Entry & entry)
const;
216 template <
typename T>
219 const std::string & cli_switch,
250 const std::string & cli_switch,
253 auto & entry = *entry_it;
260 if constexpr (std::is_same_v<bool, T>)
267 "' is a boolean and does not support a value but the value '",
269 "' was provided.\nDoc string: ",
280 const auto set_value = [&cli_switch](
const std::string & from,
auto & value)
282 using type =
typename std::remove_reference<
decltype(value)>::type;
291 if constexpr (std::is_same_v<type, std::string> || std::is_same_v<type, MooseEnum>)
294 value = MooseUtils::convert<type>(from,
true);
296 catch (std::exception & e)
299 mooseError(
"While parsing command line option '",
320 auto next_entry_it = std::next(entry_it);
321 if (next_entry_it !=
_entries.end())
323 const auto & next_entry = *next_entry_it;
324 if (!next_entry.used &&
325 (required || !next_entry.hit_param) &&
328 next_entry.value_separator &&
329 *next_entry.value_separator ==
"=" &&
332 const auto & next_entry = *next_entry_it;
334 entry.value = next_entry.name + *next_entry.value_separator + *next_entry.value;
335 entry.value_separator =
" ";
336 entry.raw_args.insert(
337 entry.raw_args.end(), next_entry.raw_args.begin(), next_entry.raw_args.end());
347 if constexpr (std::is_same_v<T, std::vector<std::string>>)
349 std::vector<std::string> split_values;
351 value.resize(split_values.size());
352 for (
const auto i : index_range(split_values))
353 set_value(split_values[i], value[i]);
357 set_value(*entry.value, value);
363 "' requires a value and one was not provided.\nDoc string: ",
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
This class wraps provides and tracks access to command line parameters.
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.
bool _hit_params_built
Whether or not the HIT parameters have been built (set as used)
bool _command_line_params_populated
Whether or not command line parameters have been populated.
std::list< Entry > _entries
The parsed command line entries (arguments split into name value pairs) This is a list because it is ...
const std::vector< std::string > & getArguments()
void removeArgument(const std::string &arg)
Removes an argument that must exist.
std::unique_ptr< CommandLine > initSubAppCommandLine(const std::string &multiapp_name, const std::string &subapp_name, const std::vector< std::string > &input_cli_args, const std::set< std::string > &exclude_params={})
Initializes a new CommandLine for a subapp with a MultiApp named multiapp_name and a subapp named sub...
const std::list< Entry > & getEntries() const
std::string getExecutableName() const
void populateCommandLineParams(InputParameters ¶ms)
Populates the command line input parameters from params.
void addArguments(int argc, char *argv[])
Adds arguments from raw argc and argv.
bool _has_parsed
Whether or not the Parser has parsed yet.
void addArgument(const std::string &arg)
Adds a single argument.
std::string getExecutableNameBase() const
std::list< Entry >::const_iterator findCommandLineParam(const std::string &name) const
std::string formatEntry(const Entry &entry) const
std::vector< std::string > _argv
Storage for the raw argv.
bool hasArgument(const std::string &arg) const
void parse()
Performs the parsing, which is the combining of arguments into [name, value] pairs.
void printUsage() const
Print the usage info for this command line.
std::vector< std::string > buildHitParams()
std::map< std::string, CommandLineParam > _command_line_params
The command line parameters, added by populateCommandLineParams()
std::vector< std::string > unusedHitParams(const Parallel::Communicator &comm) const
Returns the HIT command line arguments that are not used.
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)
bool _throw_on_error
Variable to turn on exceptions during mooseError(), should only be used within MOOSE unit tests or wh...
Stores information pertaining to a command line InputParameter.
std::string description
The description (doc string) for the parameter.
InputParameters::CommandLineMetadata metadata
The command line metadata for the parameter.
Stores name/value pairs for each command line argument.
std::optional< std::string > value
The value, i.e. ["-foo=bar"] -> "bar" or ["-foo"] -> empty, if any.
std::optional< std::string > subapp_name
The name of the subapp, if any (with subapp:something=value syntax)
std::optional< std::string > value_separator
The string that separates the value, if a value exists (space or =)
std::vector< std::string > raw_args
The raw arguments that represent these split values.
bool hit_param
Whether or not this parameter is recognized as a HIT parameter.
bool used
Whether or not this set of arguments was used.
bool global
Whether or not this parameter is global (passed to MultiApps)
std::string name
The name, i.e, ["-foo=bar"] -> "-foo" or ["--foo", "bar"] -> "--foo".