Go to the documentation of this file.
57 CommandOption::CommandOption(
61 const std::string& loOpt,
62 const std::string& desc,
65 : optFlag(of), optType(ot),
66 shortOpt(shOpt), longOpt(loOpt), description(desc),
67 required(req), count(0), maxCount(0), order(0),
parser(
NULL)
71 if ( (shOpt == 0) && (loOpt.size() == 0) )
73 InvalidParameter exc(
"A short or long command option must be specified");
77 if ( (shOpt != 0) && !isgraph(shOpt) )
79 InvalidParameter exc(
"Invalid short command option character");
83 for (
size_t i =
longOpt.size(); i > 0; --i )
87 InvalidParameter exc(
"Invalid long command option character");
92 optVectorList.push_back(
this);
102 toReturn += string(
"-") + string(1,
shortOpt);
104 toReturn += string(
" | --") +
longOpt;
108 toReturn += string(
"--") +
longOpt;
117 string toReturn(
" ");
120 toReturn += string(
"-") + string(1,
shortOpt);
123 toReturn += string(
", --") +
longOpt;
135 toReturn += string(
" --") +
longOpt;
145 struct option o = {longOpt.c_str(), optFlag,
NULL, 0};
160 if (
order.size() == 0)
163 if (idx == (
unsigned long)-1)
166 if (idx >=
order.size())
175 std::vector<std::string>::const_iterator itr =
value.begin();
176 while(itr !=
value.end())
178 out << *itr << std::endl;
217 out <<
"\t\tUp to " <<
maxCount <<
" may be used on the command line."
236 return "Required trailing argument was not found.";
248 vector<string>::size_type vecindex;
249 for(vecindex = 0; vecindex <
value.size(); vecindex++)
253 string errstr(
"Argument for ");
255 errstr += string(
" should be a digit string.");
270 vector<string>::size_type vecindex;
271 for(vecindex = 0; vecindex <
value.size(); vecindex++)
275 string errstr(
"Argument for ");
277 errstr += string(
" should be a decimal string.");
292 vector<string>::size_type vecindex;
293 for(vecindex = 0; vecindex <
value.size(); vecindex++)
297 string errstr(
"Argument for ");
299 errstr += string(
" should be an alphabetic string.");
317 string errstr(
"Only one of the following options may be specified: ");
319 bool touched =
false;
321 for (
size_t i = 0; i <
optionVec.size(); i++)
347 InvalidParameter exc(
"Invalid option address");
360 string errstr(
" of the following options must be specified: ");
365 for (CommandOptionVec::size_type i = 0; i <
optionVec.size(); i++)
370 errstr +=
optionVec[i]->getOptionString();
374 return fewerrstr + errstr;
376 return manyerrstr + errstr;
383 std::vector<CommandOption*> rv;
385 for (CommandOptionVec::size_type i = 0; i <
optionVec.size(); i++)
400 InvalidParameter exc(
"Invalid option address");
410 string errstr(
"One of the following options must be specified: ");
413 for (
size_t i = 0; i <
optionVec.size(); i++)
419 errstr +=
optionVec[i]->getOptionString();
432 for (
size_t i = 0; i <
optionVec.size(); i++)
446 string errstr(
"The following options must be used together: ");
447 bool found =
false, notFound =
false;
449 for (
size_t i = 0; i <
optionVec.size(); i++)
457 errstr +=
optionVec[i]->getOptionString();
460 if (found && notFound)
468 unsigned long rv = 0;
469 for (
size_t i = 0; i <
optionVec.size(); i++)
485 InvalidParameter exc(
"Invalid parent address");
490 InvalidParameter exc(
"Invalid child address");
504 errstr =
"Null requiree (parent) for CommandOptionDependent";
506 errstr =
"Null requirer (child) for CommandOptionDependent";
520 for (
size_t i = 0; i <
optionVec.size(); i++)
533 unsigned long rv = 0;
534 for (
size_t i = 0; i <
optionVec.size(); i++)
542 unsigned long rv = 0;
543 for (
size_t i = 0; i <
optionVec.size(); i++)
virtual std::string getOptionString() const
virtual std::string checkArguments()
@ stdType
The argument of this option can be any type.
std::string longOpt
The string for the long option (for example, "--foo").
bool required
Whether or not this is a required command line option.
std::string toGetoptShortOption() const
Returns a string for use with getopt.
std::string description
The description for the help text.
std::ostream & displayUsageDoxygen(std::ostream &out)
CommandOptionVec defaultCommandOptionList
unsigned long getOrder(unsigned long idx=-1) const
virtual std::string checkArguments()
void addOption(CommandOption *opt)
Add an option to the list of mutually exclusive options.
CommandOptionDependent()
Default Constructor.
bool isAlphaString(const std::string &s)
virtual void printHelp(std::ostream &out, bool pretty=true)
const CommandOption * requirer
virtual std::string checkArguments()
virtual unsigned long getCount() const
returns the sum of all encapsulated option counts if all are in use, zero otherwise.
virtual std::string checkArguments()
virtual std::string getArgString() const
Returns a string with the argument format.
virtual unsigned long getCount() const
virtual std::string checkArguments()
std::string asString(IonexStoreStrategy e)
Convert a IonexStoreStrategy to a whitespace-free string name.
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.
CommandOptionVec optionVec
CommandOption * whichOne() const
virtual std::string checkArguments()
virtual unsigned long getCount() const
returns the sum of all encapsulated option counts.
std::vector< CommandOption * > which() const
virtual std::string checkArguments()
char shortOpt
The character for the short option (for example, '-f').
virtual std::string checkArguments()
virtual std::string getOptionString() const
return a string containing the aggregated option strings
std::vector< CommandOption * > CommandOptionVec
CommandOptionFlag optFlag
Flag for determining whether this option has an argument or not.
std::vector< std::string > value
Any arguments passed with this option get put in here.
void addOption(CommandOption *opt)
Add an option to the list of mutually exclusive options.
virtual std::string checkArguments()
std::vector< unsigned long > order
The order in which this option was encountered on the command line.
@ hasArgument
option requires an argument
#define GNSSTK_ASSERT(CONDITION)
Provide an "ASSERT" type macro.
virtual unsigned long getCount() const
returns the sum of all encapsulated option counts if all are in use, zero otherwise.
std::string getFullOptionString() const
CommandOptionVec optionVec
bool isDecimalString(const std::string &s)
#define GNSSTK_THROW(exc)
std::ostream & displayUsage(std::ostream &out, bool doPretty=true)
CommandOptionParser * parser
virtual std::string checkArguments()
const CommandOption * requiree
bool isDigitString(const std::string &s)
std::string & prettyPrint(std::string &aStr, const std::string &lineDelim="\n", const std::string &indent="", const std::string &firstIndent=" ", const std::string::size_type len=80, const char wordDelim=' ')
gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:38