This class wraps provides and tracks access to command line parameters. More...
#include <CommandLine.h>
Classes | |
struct | CommandLineParam |
Stores information pertaining to a command line InputParameter. More... | |
struct | Entry |
Stores name/value pairs for each command line argument. More... | |
Public Types | |
using | ArgumentType = InputParameters::CommandLineMetadata::ArgumentType |
Public Member Functions | |
CommandLine () | |
CommandLine (int argc, char *argv[]) | |
CommandLine (const std::vector< std::string > &args) | |
virtual | ~CommandLine () |
void | addArguments (int argc, char *argv[]) |
Adds arguments from raw argc and argv. More... | |
void | addArgument (const std::string &arg) |
Adds a single argument. More... | |
void | addArguments (const std::vector< std::string > &args) |
Adds arguments from a vector. More... | |
bool | hasArgument (const std::string &arg) const |
void | removeArgument (const std::string &arg) |
Removes an argument that must exist. More... | |
void | parse () |
Performs the parsing, which is the combining of arguments into [name, value] pairs. More... | |
bool | hasParsed () const |
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 subapp_name . More... | |
std::string | buildHitParams () |
const std::vector< std::string > & | getArguments () |
void | populateCommandLineParams (InputParameters ¶ms) |
Populates the command line input parameters from params . More... | |
auto | begin () const |
auto | end () const |
const std::list< Entry > & | getEntries () const |
std::string | getExecutableName () const |
std::string | getExecutableNameBase () const |
void | printUsage () const |
Print the usage info for this command line. More... | |
std::vector< std::string > | unusedHitParams (const Parallel::Communicator &comm) const |
Returns the HIT command line arguments that are not used. More... | |
std::list< Entry >::const_iterator | findCommandLineParam (const std::string &name) const |
std::string | formatEntry (const Entry &entry) const |
template<typename T > | |
void | setCommandLineParam (std::list< CommandLine::Entry >::iterator entry_it, const CommandLineParam ¶m, const std::string &cli_switch, T &value) |
Private Member Functions | |
std::list< Entry > & | getEntries () |
template<typename T > | |
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 . More... | |
std::list< Entry >::iterator | findCommandLineParam (const std::string &name) |
Private Attributes | |
std::vector< std::string > | _argv |
Storage for the raw argv. More... | |
std::list< Entry > | _entries |
The parsed command line entries (arguments split into name value pairs) This is a list because it is necessary to combine Entry objects later on. More... | |
std::map< std::string, CommandLineParam > | _command_line_params |
The command line parameters, added by populateCommandLineParams() More... | |
bool | _has_parsed = false |
Whether or not the Parser has parsed yet. More... | |
bool | _command_line_params_populated = false |
Whether or not command line parameters have been populated. More... | |
This class wraps provides and tracks access to command line parameters.
Definition at line 29 of file CommandLine.h.
Definition at line 32 of file CommandLine.h.
CommandLine::CommandLine | ( | ) |
Definition at line 26 of file CommandLine.C.
CommandLine::CommandLine | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 27 of file CommandLine.C.
CommandLine::CommandLine | ( | const std::vector< std::string > & | args | ) |
Definition at line 28 of file CommandLine.C.
|
virtual |
Definition at line 198 of file CommandLine.C.
void CommandLine::addArgument | ( | const std::string & | arg | ) |
Adds a single argument.
Definition at line 38 of file CommandLine.C.
Referenced by addArguments().
Adds arguments from raw argc and argv.
Definition at line 31 of file CommandLine.C.
Referenced by CommandLine().
void CommandLine::addArguments | ( | const std::vector< std::string > & | args | ) |
Adds arguments from a vector.
Definition at line 45 of file CommandLine.C.
|
inline |
Definition at line 145 of file CommandLine.h.
Referenced by initSubAppCommandLine(), and parse().
std::string CommandLine::buildHitParams | ( | ) |
This will also mark all found HIT parameters as used.
Definition at line 239 of file CommandLine.C.
|
inline |
Definition at line 149 of file CommandLine.h.
Referenced by initSubAppCommandLine(), and parse().
std::list< CommandLine::Entry >::const_iterator CommandLine::findCommandLineParam | ( | const std::string & | name | ) | const |
name
, if any. Definition at line 452 of file CommandLine.C.
Referenced by populateCommandLineParams().
|
private |
name
, if any. Definition at line 471 of file CommandLine.C.
std::string CommandLine::formatEntry | ( | const Entry & | entry | ) | const |
Definition at line 479 of file CommandLine.C.
|
inline |
Definition at line 132 of file CommandLine.h.
Referenced by Moose::createMooseApp(), and Moose::PetscSupport::petscSetupOutput().
const std::list< CommandLine::Entry > & CommandLine::getEntries | ( | ) | const |
Definition at line 185 of file CommandLine.C.
Referenced by buildHitParams(), findCommandLineParam(), initSubAppCommandLine(), and unusedHitParams().
|
private |
Definition at line 192 of file CommandLine.C.
std::string CommandLine::getExecutableName | ( | ) | const |
Definition at line 373 of file CommandLine.C.
Referenced by getExecutableNameBase(), and printUsage().
std::string CommandLine::getExecutableNameBase | ( | ) | const |
Definition at line 383 of file CommandLine.C.
bool CommandLine::hasArgument | ( | const std::string & | arg | ) | const |
arg
is contained Definition at line 52 of file CommandLine.C.
|
inline |
Definition at line 105 of file CommandLine.h.
Referenced by addArgument(), getEntries(), parse(), and removeArgument().
std::unique_ptr< CommandLine > 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 subapp_name
.
The arguments input_cli_args
are the additional arguments to apply to the subapp, such as those that have been specified in the MultiApp params (cli_args param).
This will apply all global parameters from this parent application and all HIT CLI parameters that have the same.
Definition at line 201 of file CommandLine.C.
void CommandLine::parse | ( | ) |
Performs the parsing, which is the combining of arguments into [name, value] pairs.
Must be called before extracing anything from the CommandLine.
Definition at line 68 of file CommandLine.C.
Referenced by AppFactory::createAppShared(), and Moose::createMooseApp().
void CommandLine::populateCommandLineParams | ( | InputParameters & | params | ) |
Populates the command line input parameters from params
.
Will throw errors when conversions fail and may combine entires in _entries if some are found that can be combined.
Definition at line 293 of file CommandLine.C.
Referenced by AppFactory::createAppShared(), and Moose::createMooseApp().
void CommandLine::printUsage | ( | ) | const |
Print the usage info for this command line.
Definition at line 393 of file CommandLine.C.
void CommandLine::removeArgument | ( | const std::string & | arg | ) |
Removes an argument that must exist.
Definition at line 58 of file CommandLine.C.
|
private |
Sets an InputParameters command line option at value
.
Will report an error if string -> value conversions fail or if the parameter requires a value and one was not found.
entry_it | Iterator to the Entry object that we're extracting from |
param | The internal metadata for the command line parameter |
cli_switch | The command line switch for the parameter (-t, –timing, etc) |
value | The value that we want to fill into |
void CommandLine::setCommandLineParam | ( | std::list< CommandLine::Entry >::iterator | entry_it, |
const CommandLineParam & | param, | ||
const std::string & | cli_switch, | ||
T & | value | ||
) |
Definition at line 240 of file CommandLine.h.
std::vector< std::string > CommandLine::unusedHitParams | ( | const Parallel::Communicator & | comm | ) | const |
Returns the HIT command line arguments that are not used.
The HIT command line arguments are considered used when they are accumulated in buildHitParams().
The commmunicator is needed because we need to sync this in parallel due to the fact that sub apps could only be created on a subset of processors.
Definition at line 428 of file CommandLine.C.
|
private |
Storage for the raw argv.
Definition at line 223 of file CommandLine.h.
Referenced by addArgument(), getArguments(), hasArgument(), parse(), and removeArgument().
|
private |
The command line parameters, added by populateCommandLineParams()
Definition at line 230 of file CommandLine.h.
Referenced by findCommandLineParam(), populateCommandLineParams(), and printUsage().
|
private |
Whether or not command line parameters have been populated.
Definition at line 235 of file CommandLine.h.
Referenced by buildHitParams(), and populateCommandLineParams().
|
private |
The parsed command line entries (arguments split into name value pairs) This is a list because it is necessary to combine Entry objects later on.
Definition at line 227 of file CommandLine.h.
Referenced by begin(), end(), findCommandLineParam(), getEntries(), getExecutableName(), parse(), populateCommandLineParams(), and setCommandLineParam().
|
private |
Whether or not the Parser has parsed yet.
Definition at line 233 of file CommandLine.h.
Referenced by hasParsed(), and parse().