#include <CommandOption.hpp>
Inheritance diagram for CommandOption:

Each CommandOption represents an option you would enter at a command line. You can specify whether the option does or does not require an argument, if the option is of a certain type (string or number), then the short option (i.e. '-f') and long option ('--foo'), whether it's a required option or not, then a short description for a help display. By default, options can appear an unlimited number of times on a command line. Use setMaxCount() to set a maximum limit to this. In that case, additional appearances of that option will trigger an error once parsed.
When a CommandOption is created (not using the default constructor), it automatically adds itself to a list that will be used by gpstk::CommandOptionParser. If you want to manage your own list, pass in your own std::vector<gpstk::CommandOptionParser> with the CommandOption constructor. After parsing the command line, you can use the getValue() and getCount() methods to see what arguments the options had and how many times the option was listed on the command line.
This class is strongly connected to gpstk::CommandOptionParser, so if you change anything here, make sure you don't side affect the other.
Do not repeat characters or strings used in the short or long command options. Doing so will cause one of them not to work.
Do not reuse the CommandOption objects. Make a separate one for each option you want on the command line.
Make the description an understandable, grammatically correct sentence.
The resulting behavior of not heeding the above advice is undefined, and I take no responsibility for the results of you not taking appropriate action in light of this warning.
Definition at line 120 of file CommandOption.hpp.
Public Types | |
| enum | CommandOptionFlag { noArgument = 0, hasArgument = 1 } |
| Every option must either have or not have an argument. More... | |
| enum | CommandOptionType { trailingType, stdType, metaType } |
| This is so you can limit what type or argument an option can have. More... | |
Public Member Functions | |
| CommandOption (const CommandOptionFlag of, const CommandOptionType ot, const char shOpt, const std::string &loOpt, const std::string &desc, const bool req=false, CommandOptionVec &optVectorList=defaultCommandOptionList) | |
| Constructor. | |
| CommandOption & | setMaxCount (const unsigned long l) |
| Sets the maximum number of times this should appear on the command line. | |
| virtual std::string | getOptionString () const |
| Returns a string with the flags for this CommandOption. | |
| std::string | getFullOptionString () const |
| Returns a formatted string with the flags for this CommandOption. | |
| virtual std::string | getArgString () const |
| Returns a string with the argument format. | |
| option | toGetoptLongOption () const |
| Returns a struct option for use with getopt_long. | |
| std::string | toGetoptShortOption () const |
| Returns a string for use with getopt. | |
| virtual unsigned long | getCount () const |
| Returns the number of times this option was found on the command line. | |
| std::vector< std::string > | getValue () const |
| Returns the arguments this option had passed in from the command line. | |
| unsigned int | getOrder () const |
| the last occurance of this option. | |
| std::ostream & | dumpValue (std::ostream &out) const |
Displays this->value to the stream out. | |
| std::string | getDescription () const |
| Returns a formatted string with the description of this option. | |
| virtual std::string | checkArguments () |
| If you specified a format for the arguments (for example, digit or string), this function checks them to see if they match. | |
| virtual | ~CommandOption () |
| Destructor. | |
Protected Member Functions | |
| CommandOption () | |
| Default Constructor. | |
Protected Attributes | |
| CommandOptionFlag | optFlag |
| Flag for determining whether this option has an argument or not. | |
| CommandOptionType | optType |
| Flag for determining whether this option has a specific argument type. | |
| char | shortOpt |
| The character for the short option (for example, '-f'). | |
| std::string | longOpt |
| The string for the long option (for example, "--foo"). | |
| std::string | description |
| The description for the help text. | |
| std::vector< std::string > | value |
| Any arguments passed with this option get put in here. | |
| bool | required |
| Whether or not this is a required command line option. | |
| unsigned long | count |
| The number of times this option was encountered on the command line. | |
| unsigned long | maxCount |
| The maximum number of times this can appear on the command line. | |
| unsigned long | order |
| The order in which this option was encountered on the command line. | |
Friends | |
| class | CommandOptionParser |
| let's the CommandOptionParser see it's private parts =) | |
|
|
Every option must either have or not have an argument. There are no optional arguments because Solaris doesn't support it. Definition at line 128 of file CommandOption.hpp. |
|
|
This is so you can limit what type or argument an option can have. If specified, it will be checked when the argument is encountered. Errors will get set appropriately if there are any.
Definition at line 137 of file CommandOption.hpp. |
|
||||||||||||||||||||||||||||||||
|
Constructor.
Definition at line 158 of file CommandOption.hpp. |
|
|
Destructor.
Definition at line 228 of file CommandOption.hpp. |
|
|
Default Constructor.
Definition at line 256 of file CommandOption.hpp. |
|
|
If you specified a format for the arguments (for example, digit or string), this function checks them to see if they match. If they don't, an error string is returned. If they do, an empty string is returned.
Reimplemented in CommandOptionWithStringArg, CommandOptionWithNumberArg, CommandOptionRest, CommandOptionOneOf, CommandOptionAllOf, CommandOptionMutex, CommandOptionDependent, CommandOptionGroupOr, CommandOptionWithCommonTimeArg, CommandOptionWithPositionArg, and CommandOptionWithTimeArg. Definition at line 173 of file CommandOption.cpp. References CommandOption::count, CommandOption::getOptionString(), and CommandOption::required. Referenced by CommandOptionParser::parseOptions(). |
|
|
Displays this->value to the stream
Definition at line 121 of file CommandOption.cpp. References CommandOption::value. |
|
|
Returns a string with the argument format.
Reimplemented in CommandOptionWithStringArg, CommandOptionWithNumberArg, CommandOptionWithCommonTimeArg, CommandOptionWithPositionArg, and CommandOptionWithTimeArg. Definition at line 185 of file CommandOption.hpp. Referenced by CommandOption::getDescription(), and CommandOption::getFullOptionString(). |
|
|
Returns the number of times this option was found on the command line.
Reimplemented in CommandOptionAllOf, CommandOptionGroupOr, and CommandOptionGroupAnd. Definition at line 197 of file CommandOption.hpp. Referenced by CommandOptionDependent::checkArguments(), CommandOptionMutex::checkArguments(), CommandOptionGroupAnd::getCount(), CommandOptionGroupOr::getCount(), CommandOptionAllOf::getCount(), ObsEphReaderFramework::initialize(), InOutFramework::initialize(), and main(). |
|
|
Returns a formatted string with the description of this option.
Definition at line 137 of file CommandOption.cpp. References CommandOption::description, CommandOption::getArgString(), CommandOption::longOpt, CommandOption::maxCount, CommandOption::optFlag, gpstk::StringUtils::prettyPrint(), and CommandOption::shortOpt. |
|
|
Returns a formatted string with the flags for this CommandOption. (i.e. " -f, --foo=ARG") Definition at line 83 of file CommandOption.cpp. References CommandOption::getArgString(), CommandOption::longOpt, CommandOption::optFlag, and CommandOption::shortOpt. |
|
|
Returns a string with the flags for this CommandOption. (i.e. "-f | --foo") Reimplemented in CommandOptionGroupOr. Definition at line 65 of file CommandOption.cpp. References CommandOption::longOpt, and CommandOption::shortOpt. Referenced by CommandOptionDependent::checkArguments(), CommandOptionAllOf::checkArguments(), CommandOptionOneOf::checkArguments(), CommandOptionMutex::checkArguments(), CommandOptionWithStringArg::checkArguments(), CommandOptionWithNumberArg::checkArguments(), CommandOption::checkArguments(), CommandOptionGroupOr::getOptionString(), and CommandOptionParser::parseOptions(). |
|
|
the last occurance of this option.
Definition at line 209 of file CommandOption.hpp. |
|
|
Returns the arguments this option had passed in from the command line.
Definition at line 203 of file CommandOption.hpp. Referenced by ObsEphReaderFramework::initialize(), InOutFramework::initialize(), main(), and MinSfTest::process(). |
|
|
Sets the maximum number of times this should appear on the command line.
Definition at line 173 of file CommandOption.hpp. Referenced by ObsEphReaderFramework::initialize(). |
|
|
Returns a struct option for use with getopt_long.
Definition at line 106 of file CommandOption.cpp. Referenced by CommandOptionParser::parseOptions(). |
|
|
Returns a string for use with getopt.
Definition at line 113 of file CommandOption.cpp. References CommandOption::optFlag, and CommandOption::shortOpt. Referenced by CommandOptionParser::parseOptions(). |
|
|
let's the CommandOptionParser see it's private parts =)
Definition at line 124 of file CommandOption.hpp. |
|
|
The number of times this option was encountered on the command line.
Definition at line 248 of file CommandOption.hpp. Referenced by CommandOption::checkArguments(), and CommandOptionParser::parseOptions(). |
|
|
The description for the help text.
Definition at line 241 of file CommandOption.hpp. Referenced by CommandOptionParser::displayUsage(), and CommandOption::getDescription(). |
|
|
The string for the long option (for example, "--foo").
Definition at line 239 of file CommandOption.hpp. Referenced by CommandOption::getDescription(), CommandOption::getFullOptionString(), and CommandOption::getOptionString(). |
|
|
The maximum number of times this can appear on the command line. If it's 0, then it's unlimited. Definition at line 251 of file CommandOption.hpp. Referenced by CommandOption::getDescription(). |
|
|
Flag for determining whether this option has an argument or not.
Definition at line 232 of file CommandOption.hpp. Referenced by CommandOption::getDescription(), CommandOption::getFullOptionString(), CommandOptionParser::parseOptions(), and CommandOption::toGetoptShortOption(). |
|
|
Flag for determining whether this option has a specific argument type.
Definition at line 235 of file CommandOption.hpp. |
|
|
The order in which this option was encountered on the command line.
Definition at line 253 of file CommandOption.hpp. Referenced by CommandOptionParser::parseOptions(). |
|
|
Whether or not this is a required command line option.
Definition at line 245 of file CommandOption.hpp. Referenced by CommandOption::checkArguments(). |
|
|
The character for the short option (for example, '-f').
Definition at line 237 of file CommandOption.hpp. Referenced by CommandOption::getDescription(), CommandOption::getFullOptionString(), CommandOption::getOptionString(), and CommandOption::toGetoptShortOption(). |
|
|
Any arguments passed with this option get put in here.
Definition at line 243 of file CommandOption.hpp. Referenced by CommandOption::dumpValue(), and CommandOptionParser::parseOptions(). |
1.3.9.1