 |
PhoenixMock
1.8.7
Tools to split/merge/print mock used in Phoenix
|
Go to the documentation of this file.
15 Option::Option(
const std::string & longName,
const std::string & shortName,
const std::string & docString)
16 :p_longName(longName), p_shortName(shortName), p_value(
""), p_isRequired(false), p_docString(docString)
27 Option::Option(
const std::string & longName,
const std::string & shortName,
const OptionValue & value,
const std::string & docString)
28 :p_longName(longName), p_shortName(shortName), p_value(value), p_isRequired(false), p_docString(docString)
40 Option::Option(
const std::string & longName,
const std::string & shortName,
const OptionValue & value,
bool isRequired,
const std::string & docString)
41 :p_longName(longName), p_shortName(shortName), p_value(value), p_isRequired(isRequired), p_docString(docString)
52 Option::Option(
const std::string & longName,
const std::string & shortName,
bool isRequired,
const std::string & docString)
53 :p_longName(longName), p_shortName(shortName), p_isRequired(isRequired), p_docString(docString)
93 if(vecValue.size() == 0lu){
return;}
94 VecValue::const_iterator it(vecValue.begin());
97 while(it != vecValue.end()){
98 std::cout <<
", " << *it;
108 std::cout << indentation;
125 std::cout << std::endl;
127 if(vecDefaultValue.size()){
128 std::cout << indentation <<
"\tDefault value : '";
130 std::cout <<
"'" << std::endl;
133 if(vecPossibleValue.size()){
134 std::cout << indentation <<
"\tPossible values : ";
136 std::cout << std::endl;
138 if(
p_isRequired){std::cout << indentation <<
"\tThis argument has to be set" << std::endl;}
139 else{std::cout << indentation <<
"\tThis argument is optional" << std::endl;}
140 if(
p_isAllowEmpty){std::cout << indentation <<
"\tThis argument can have an empty value" << std::endl;}
141 else{std::cout << indentation <<
"\tThis argument cannot have an empty value" << std::endl;}
256 std::cerr <<
termRed() <<
"Missing arguement ";
284 if(cursorOption ==
""){
285 possibleOption += longOption +
" ";
288 possibleOption += longOption +
" ";
294 if(cursorOption ==
""){
295 possibleOption += shortOption +
" ";
298 possibleOption += shortOption +
" ";
341 if(
parser.isEndOfOption()){
return true;}
342 if(optionName ==
""){
return false;}
343 std::string & currentOption =
parser.getCurrentOption();
344 std::string longOption(prefix + optionName);
345 size_t sizeLongOption(longOption.size());
347 if(currentOption == longOption){
354 bool valueOk(
true), isInitialised(
false);
356 while(!
parser.isEndOfOption() && valueOk){
357 std::string & currentOption =
parser.getCurrentOption();
358 if(currentOption ==
""){
363 isInitialised =
true;
365 throw std::runtime_error(
"Option::parsePartOption : pass empty value to option '" + longOption +
"' which does not expect STRING");
368 if(currentOption[0] ==
'-'){
374 isInitialised =
true;
379 throw std::runtime_error(
"Option::parsePartOption : expect value after option '" + longOption +
"'");
383 if(currentOption[sizeLongOption] ==
'='){
385 throw std::runtime_error(
"Option::parsePartOption : the option '"+currentOption+
"' does not have value");
387 if(currentOption.size() == sizeLongOption + 1lu){
389 throw std::runtime_error(
"Option::parsePartOption : problem with the option '"+currentOption+
"' because it ends with a '=' and not a value");
393 std::string value(currentOption.substr(sizeLongOption + 1lu));
410 throw std::runtime_error(
"Option::checkAlreadyParsed : option '" + longOption +
"' already exists");
OptionValue p_value
Value of the Option.
bool isRequired() const
Get if the option is required.
void setIsParsed(bool isParsed)
Say if the Option has been parsed or not.
std::string convertOptionTypeToString(OptionType::OptionType type)
Convert the OptionType into string.
std::string p_shortName
Short name of the Option.
void printVecString(const VecValue &vecValue)
Print a vector of value.
void setDocString(const std::string &docString)
Set the documentation string of the Option.
std::string p_longName
Long name of the Option.
bool isParsed() const
Say if the Option has been parsed or not.
bool p_isRequired
True if the option is required, false if it is optionnal.
void checkAlreadyParsed(const std::string &longOption)
Check if the Option has been already parsed.
bool checkArgument() const
Check the argument of the parser.
const OptionValue & getValue() const
Get the value of the Option.
bool p_isAllowEmpty
The option can be empty and can have a value.
bool isAllowEmpty() const
Get if the option value can be empty.
void print(const std::string &indentation="") const
Print an option.
void setLongName(const std::string &longName)
Set the long name of the option.
std::string p_firstPartParsedOption
First paet of parsed option (needed for bash completion)
OptionType::OptionType getType() const
Get the type of the OptionValue.
const VecValue & getPossibleValue() const
Get the possible values of the OptionValue.
Option & operator=(const Option &other)
Definition of equal operator of Option.
void setValue(const OptionValue &value)
Set the value of the option.
void copyOption(const Option &other)
Copy function of Option.
virtual ~Option()
Destructeur of Option.
std::string termDefault()
affiche le terminal par défaut
const std::string & getShortName() const
Get the short name of the Option.
std::string termRed()
affiche le terminal rouge
void getPossibleValue(std::string &possibleValue, const std::string &cursorOption) const
Complete the possible values of the Option.
void bashCompletionValue(std::string &strBashCompletion, const std::string &cursorOption) const
Print the possible value to the bash completion.
bool isSameBegining(const std::string &str, const std::string &beginig)
Check if two string start the same way.
void addValue(const std::string &value)
Add value of the OptionValue.
bool parseOption(ArgParser &parser)
Parse the current option with the given parser.
bool p_isParsed
Say if the option has been parsed or not.
std::string p_docString
Documentation string of the current Option.
void setShortName(const std::string &shortName)
Set the short name of the option.
const std::string & getLongName() const
Get the long name of the Option.
Option(const std::string &longName="", const std::string &shortName="", const std::string &docString="")
Default constructor of Option.
bool parsePartOption(ArgParser &parser, const std::string &prefix, const std::string &optionName)
Parse the given option with the parser.
void setIsAllowEmpty(bool isAllowEmpty)
Say if the option can be empty or not.
Describe the value of an option passed to a program.
void initialisationOption()
Initialisation function of the class Option.
const VecValue & getDefaultValue() const
Get the default value of the OptionValue.
std::vector< std::string > VecValue
Vector of values.
void setIsRequired(bool isRequired)
Set if the option is required.
void getPossibleOption(std::string &possibleOption, const std::string &cursorOption) const
Get the possible options for the bash completion.
const std::string & getDocString() const
Get the documentation string of the Option.
Parse the list of arguments passed to a program.