LOOS 4.1.0
The Lightweight Object Oriented Structural analysis library/toolkit
|
Provides simple way to add command-line arguments (required options) More...
#include <OptionsFramework.hpp>
Public Member Functions | |
RequiredArguments (const std::string &argname, const std::string &argdesc) | |
void | addArgument (const std::string &name, const std::string &description) |
Add a required argument given a name (tag) and a description (currently unused) | |
void | addVariableArguments (const std::string &name, const std::string &description) |
Add a required argument that can be an arbitrary number of items. | |
std::string | value (const std::string &s) const |
Retrieve the value for an argument. | |
std::vector< std::string > | variableValues (const std::string &s) const |
Retrieve the variable-number argument. | |
Public Member Functions inherited from loos::OptionsFramework::OptionsPackage | |
virtual void | addGeneric (po::options_description &opts) |
Appends generic options (those that the user can see) | |
Provides simple way to add command-line arguments (required options)
This class handles required command-line options (also known as command line arguments). Each argument is defined by a string tag and a description and is parsed from the command line as a string. Arguments are added via the addOption() method and the values are retrieved using value().
Since these are required options, the class will automatically generate a parsing error if any argument is unset.
The value returned for options are strings and must be parsed into the appropriate type. A simple way to do this is to use loos::parseStringAs<>.
Example:
The case where one or more arguments are required is supported via the RequiredArguments::addVariableArguments() and RequiredArguments::variableValues(). If this feature is used, then the RequiredArguments object must be the last OptionsPackage chained together in the AggregateOptions object.
void loos::OptionsFramework::RequiredArguments::addVariableArguments | ( | const std::string & | name, |
const std::string & | description ) |
Add a required argument that can be an arbitrary number of items.
This argument will always appear at the end of the command line, after all other required arguments. It also means that the RequiredOptions object should be the last one added to the AggregateOptions object, otherwise any subsequence positional arguments will be missed.
Example: