12 :p_longName(
""), p_shortName(
""), p_value(
""), p_isRequired(false), p_docString(
"")
23 :p_longName(longName), p_shortName(shortName), p_value(
""), p_isRequired(false), p_docString(docString)
35 :p_longName(longName), p_shortName(shortName), p_value(value), p_isRequired(false), p_docString(docString)
48 :p_longName(longName), p_shortName(shortName), p_value(value), p_isRequired(isRequired), p_docString(docString)
60 :p_longName(longName), p_shortName(shortName), p_isRequired(isRequired), p_docString(docString)
100 if(vecValue.size() == 0lu){
return;}
101 PVecString::const_iterator it(vecValue.begin());
104 while(it != vecValue.end()){
105 std::cout <<
", " << *it;
115 std::cout << indentation;
132 std::cout << std::endl;
134 if(vecDefaultValue.size()){
135 std::cout << indentation <<
"\tDefault value : '";
137 std::cout <<
"'" << std::endl;
140 if(vecPossibleValue.size()){
141 std::cout << indentation <<
"\tPossible values : ";
143 std::cout << std::endl;
145 if(
p_isRequired){std::cout << indentation <<
"\tThis argument has to be set" << std::endl;}
146 else{std::cout << indentation <<
"\tThis argument is optional" << std::endl;}
147 if(
p_isAllowEmpty){std::cout << indentation <<
"\tThis argument can have an empty value" << std::endl;}
148 else{std::cout << indentation <<
"\tThis argument cannot have an empty value" << std::endl;}
263 std::cerr <<
termRed() <<
"Missing arguement ";
291 if(cursorOption ==
""){
292 possibleOption += longOption +
" ";
295 possibleOption += longOption +
" ";
301 if(cursorOption ==
""){
302 possibleOption += shortOption +
" ";
305 possibleOption += shortOption +
" ";
348 if(optionName ==
""){
return false;}
350 PString longOption(prefix + optionName);
351 size_t sizeLongOption(longOption.size());
353 if(currentOption == longOption){
360 bool valueOk(
true), isInitialised(
false);
364 if(currentOption ==
""){
369 isInitialised =
true;
371 throw std::runtime_error(
"Option::parsePartOption : pass empty value to option '" + longOption +
"' which does not expect STRING");
374 if(currentOption[0] ==
'-'){
380 isInitialised =
true;
385 throw std::runtime_error(
"Option::parsePartOption : expect value after option '" + longOption +
"'");
389 if(currentOption[sizeLongOption] ==
'='){
391 throw std::runtime_error(
"Option::parsePartOption : the option '"+currentOption+
"' does not have value");
393 if(currentOption.size() == sizeLongOption + 1lu){
395 throw std::runtime_error(
"Option::parsePartOption : problem with the option '"+currentOption+
"' because it ends with a '=' and not a value");
399 PString value(currentOption.substr(sizeLongOption + 1lu));
416 throw std::runtime_error(
"Option::checkAlreadyParsed : option '" + longOption +
"' already exists");
PString convertOptionTypeToString(OptionType::OptionType type)
Convert the OptionType into PString.
void printVecString(const PVecString &vecValue)
Print a vector of value.
std::vector< PString > PVecString
Parse the list of arguments passed to a program.
const PString & getCurrentOption() const
Get the current option.
void getNextOption()
Move to the next option.
bool isEndOfOption() const
Say if is it the end of the options.
Describe the value of an option passed to a program.
void bashCompletionValue(PString &strBashCompletion, const PString &cursorOption) const
Print the possible value to the bash completion.
void addValue(const PString &value)
Add value of the OptionValue.
OptionType::OptionType getType() const
Get the type of the OptionValue.
const PVecString & getDefaultValue() const
Get the default value of the OptionValue.
const PVecString & getPossibleValue() const
Get the possible values of the OptionValue.
Describes an option passed to a program.
virtual ~Option()
Destructeur of Option.
void setIsParsed(bool isParsed)
Say if the Option has been parsed or not.
void setIsAllowEmpty(bool isAllowEmpty)
Say if the option can be empty or not.
bool p_isAllowEmpty
The option can be empty and can have a value.
const PString & getLongName() const
Get the long name of the Option.
void checkAlreadyParsed(const PString &longOption)
Check if the Option has been already parsed.
bool parsePartOption(ArgParser &parser, const PString &prefix, const PString &optionName)
Parse the given option with the parser.
void getPossibleOption(PString &possibleOption, const PString &cursorOption) const
Get the possible options for the bash completion.
void initialisationOption()
Initialisation function of the class Option.
void setLongName(const PString &longName)
Set the long name of the option.
bool parseOption(ArgParser &parser)
Parse the current option with the given parser.
PString p_shortName
Short name of the Option.
const OptionValue & getValue() const
Get the value of the Option.
bool isParsed() const
Say if the Option has been parsed or not.
void copyOption(const Option &other)
Copy function of Option.
bool p_isRequired
True if the option is required, false if it is optionnal.
OptionValue p_value
Value of the Option.
const PString & getDocString() const
Get the documentation string of the Option.
void setShortName(const PString &shortName)
Set the short name of the option.
bool checkArgument() const
Check the argument of the parser.
bool p_isParsed
Say if the option has been parsed or not.
PString p_firstPartParsedOption
First paet of parsed option (needed for bash completion)
void setIsRequired(bool isRequired)
Set if the option is required.
PString p_longName
Long name of the Option.
const PString & getShortName() const
Get the short name of the Option.
void setValue(const OptionValue &value)
Set the value of the option.
bool isAllowEmpty() const
Get if the option value can be empty.
Option & operator=(const Option &other)
Definition of equal operator of Option.
void getPossibleValue(PString &possibleValue, const PString &cursorOption) const
Complete the possible values of the Option.
PString p_docString
Documentation string of the current Option.
void print(const PString &indentation="") const
Print an option.
void setDocString(const PString &docString)
Set the documentation string of the Option.
Option()
Default constructor of Option.
bool isRequired() const
Get if the option is required.
bool isSameBegining(const PString &beginStr) const
Say if the current PString has the same begining of beginStr.
std::string termDefault()
affiche le terminal par défaut
std::string termRed()
affiche le terminal rouge