18 #include "libmesh/parallel.h" 77 void addOption(
const std::string & name, Option cli_opt);
84 bool search(
const std::string & option_name);
87 bool search(
const std::string & option_name, T & argument);
90 bool search(
const std::string & option_name, std::vector<T> & argument);
96 std::vector<std::string>::const_iterator
find(
const std::string & option_name)
const;
99 std::vector<std::string>::const_iterator
begin()
const;
102 std::vector<std::string>::const_iterator
end()
const;
128 std::set<int>
unused(
const Parallel::Communicator & comm)
130 comm.set_union(
_hiti);
146 template <
typename T>
147 void setArgument(std::stringstream & stream, T & argument);
152 template <
typename T>
153 void setArgument(std::stringstream & stream, T & argument,
const std::string & cli_switch);
171 template <
typename T>
178 template <
typename T>
192 catch (std::exception & e)
195 mooseError(
"While parsing command line argument '",
208 void CommandLine::setArgument<std::string>(std::stringstream & stream, std::string & argument);
211 void CommandLine::setArgument<MooseEnum>(std::stringstream & stream,
MooseEnum & argument);
213 template <
typename T>
219 const auto & option = pos->second;
220 for (
const auto & cli_switch : option.cli_switch)
223 const auto & arg =
_args[arg_i];
225 if (arg == cli_switch)
231 else if (arg_i + 1 <
_args.size())
233 std::stringstream ss;
234 ss <<
_args[arg_i + 1];
238 else if (option.argument_type == ArgumentType::REQUIRED)
242 "' requires a value and one was not provided.");
248 if (pos->second.required)
250 Moose::err <<
"Required parameter: " << option_name <<
" missing\n";
258 template <
typename T>
262 std::map<std::string, Option>::iterator pos =
_cli_options.find(option_name);
265 for (
unsigned int i = 0; i < pos->second.cli_switch.size(); ++i)
267 for (
size_t j = 0; j <
_argv.size(); j++)
271 if (arg == pos->second.cli_switch[i])
277 argument.push_back(T());
278 else if (pos->second.argument_type == ArgumentType::REQUIRED)
279 mooseError(
"Adding vector command line parameters with required arguments is not " 280 "currently supported");
282 while (j + 1 <
_argv.size() &&
_argv[j + 1][0] !=
'-' &&
283 _argv[j + 1].find(
"=") == std::string::npos)
285 std::stringstream ss;
290 argument.push_back(item);
297 if (pos->second.required && argument.empty())
299 Moose::err <<
"Required parameter: " << option_name <<
" missing\n";
std::map< std::string, Option > _cli_options
Command line options.
void markHitParam(int argi)
std::vector< std::string > cli_switch
This gets filled in automagicaly when calling addOption()
std::string getExecutableName() const
Get the executable name.
std::set< int > unused(const Parallel::Communicator &comm)
std::vector< std::string >::const_iterator find(const std::string &option_name) const
Returns an iterator to the underlying argument vector to the position of the option or end if the opt...
void addArgument(std::string)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void markHitParamUsed(int argi)
void printUsage() const
Print the usage info for this command line.
std::set< int > _hiti
indices of CLI args that are HIT syntax parameters
void initForMultiApp(const std::string &)
Removes multiapp parameters not associated with the supplied name.
This class wraps provides and tracks access to command line parameters.
void populateInputParams(InputParameters ¶ms)
ArgumentType argument_type
std::vector< std::string >::const_iterator begin() const
std::vector< std::string > _argv
Storage for the raw argv.
void addOption(const std::string &name, Option cli_opt)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
std::set< int > _used_hiti
indices of CLI args that have been marked as used
void setArgument(std::stringstream &stream, T &argument)
Helper for setting the argument value, allows specialization.
void addCommandLineOptionsFromParams(const InputParameters ¶ms)
bool search(const std::string &option_name)
This routine searches the command line for the given option "handle" and returns a boolean indicating...
std::vector< std::string > cli_syntax
std::vector< std::string >::const_iterator end() const
std::vector< std::string > _args
bool _throw_on_error
Variable to turn on exceptions during mooseError(), should only be used within MOOSE unit tests or wh...
auto index_range(const T &sizable)
const std::vector< std::string > & getArguments()
Return the raw argv arguments as a vector.
std::string getExecutableNameBase() const
Get the exectuable name base (the name without the -[opt,oprof,devel,dbg])
void addArguments(int argc, char *argv[])