ewmscp
..
|
class that contains the parser, i.e. does that option handling More...
#include <Options.h>
Public Member Functions | |
parser (const std::string &aDescription="", const std::string &aTrailer="", const std::vector< std::string > &aSearchPaths={"/etc/", "~/.", "~/.config/", "./."}) | |
~parser () | |
bool | fIsParsingDone () const |
void | fSetMessageStream (std::ostream *aStream) |
void | fSetErrorStream (std::ostream *aStream) |
std::ostream & | fGetErrorStream () const |
void | fSetHelpReturnValue (int aValue) |
int | fGetHelpReturnValue () const |
virtual void | fComplainAndLeave (bool aWithHelp=true) |
print help (if required) and exit. More... | |
void | fSetAssignmentChars (char aPrimary='=', char aSecondary=':') |
char | fGetSecondaryAssignment () const |
virtual void | fRequire (const base *aOtherOption) |
virtual void | fRequire (std::vector< const base * > aOtherOptions) |
const std::vector< std::string > & | fParse (int argc, const char *argv[]) |
parse the options on the command line More... | |
const std::vector< std::string > & | fParse (int argc, char *argv[]) |
other signature for fParse, when argv needs to be without const due to external constraints More... | |
void | fHelp () |
print help, normally automatically called by the –help option or in case of problems. More... | |
void | fWriteCfgFile (const std::string &aFileName) |
void | fReadCfgFile (const std::string &aFileName, const options::internal::sourceItem &aSource, bool aMayBeAbsent=false) |
void | fSetExecutableName (const char *aName) |
void | fSetMinusMinusStartsExtraList () |
switch on use of – to separate a trailer on the command line that is not to be parsed More... | |
const std::vector< std::string > & | fGetStuffAfterMinusMinus () |
get trailong part of command line as a vector od strings, requires that fSetMinusMinusStartsExtraList was called before parsing. More... | |
const std::string & | fGetProgName () const |
Static Public Member Functions | |
static parser * | fGetInstance () |
get the only allwed instance of the option parser. More... | |
static void | fPrintEscapedString (std::ostream &aStream, const std::string &aString) |
static void | fReCaptureEscapedString (std::string &aDest, const std::string &aSource) |
Protected Member Functions | |
void | fReadConfigFiles () |
read config files if present More... | |
void | fPrintOptionHelp (std::ostream &aMessageStream, const base &aOption, std::size_t aMaxName, std::size_t aMaxExplain, size_t lineLenght) const |
void | fCheckConsistency () |
Protected Attributes | |
const std::string | lDescription |
const std::string | lTrailer |
const std::vector< std::string > | lSearchPaths |
std::vector< std::string > | lUnusedOptions |
std::vector< std::string > | lStuffAfterMinusMinus |
std::set< const base * > | lRequiredOptions |
bool | lMinusMinusJustEndsOptions |
std::ostream * | lMessageStream |
std::ostream * | lErrorStream |
std::string | lProgName |
std::string | lExecutableName |
int | lHelpReturnValue |
char | lPrimaryAssignment |
char | lSecondaryAssignment |
bool | lParsingIsDone |
Static Protected Attributes | |
static parser * | gParser = nullptr |
class that contains the parser, i.e. does that option handling
once contructed with the header part and the trailer part of the help text, together with the list of search paths for config files the option parser can then be used to parse the command line options.
options::parser::parser | ( | const std::string & | aDescription = "" , |
const std::string & | aTrailer = "" , |
||
const std::vector< std::string > & | aSearchPaths = {"/etc/", "~/.", "~/.config/", "./."} |
||
) |
Definition at line 90 of file Options.cpp.
References fComplainAndLeave(), fSetAssignmentChars(), gParser, lErrorStream, lHelpReturnValue, lMessageStream, and lMinusMinusJustEndsOptions.
options::parser::~parser | ( | ) |
|
protected |
Definition at line 323 of file Options.cpp.
References fComplainAndLeave(), fGetErrorStream(), options::base::fGetOptionMap(), and lRequiredOptions.
Referenced by fParse().
|
virtual |
print help (if required) and exit.
this function can be overloaded in a class derived from parser, for example when one instead of calling exit() wants to throw an exception. as normaly the call to exit() is what is required this is the default action.
Definition at line 365 of file Options.cpp.
References fGetErrorStream(), and fGetProgName().
Referenced by fCheckConsistency(), fParse(), options::internal::fParseTimePointString(), options::internal::parseNumberAndUnit(), and parser().
std::ostream & options::parser::fGetErrorStream | ( | ) | const |
Definition at line 121 of file Options.cpp.
References lErrorStream.
Referenced by fCheckConsistency(), fComplainAndLeave(), fParse(), options::internal::fParseTimePointString(), fReadCfgFile(), and options::internal::parseNumberAndUnit().
|
inline |
Definition at line 398 of file Options.h.
References lHelpReturnValue.
|
static |
get the only allwed instance of the option parser.
Definition at line 144 of file Options.cpp.
References gParser.
Referenced by options::base::base(), options::internal::fParseTimePointString(), options::map< T >::fSetMe(), options::internal::OptionWriteCfgFile::fSetMe(), options::internal::OptionReadCfgFile< mayBeMissing >::fSetMe(), options::internal::OptionHelp::fSetMeNoarg(), options::map< T >::fWriteCfgLines(), options::map< T >::fWriteValue(), and options::internal::parseNumberAndUnit().
|
inline |
Definition at line 436 of file Options.h.
References lProgName.
Referenced by fComplainAndLeave().
|
inline |
Definition at line 403 of file Options.h.
References lSecondaryAssignment.
Referenced by options::map< T >::fWriteCfgLines(), and options::map< T >::fWriteValue().
|
inline |
get trailong part of command line as a vector od strings, requires that fSetMinusMinusStartsExtraList was called before parsing.
Definition at line 433 of file Options.h.
References lStuffAfterMinusMinus.
Referenced by main().
void options::parser::fHelp | ( | ) |
print help, normally automatically called by the –help option or in case of problems.
Definition at line 724 of file Options.cpp.
References options::base::fGetOptionMap(), options::internal::positional_base::fGetPositonalArgs(), fPrintOptionHelp(), lDescription, lMessageStream, lProgName, lSearchPaths, and lTrailer.
Referenced by options::internal::OptionHelp::fSetMeNoarg(), and main().
bool options::parser::fIsParsingDone | ( | ) | const |
Definition at line 110 of file Options.cpp.
References lParsingIsDone.
const std::vector< std::string > & options::parser::fParse | ( | int | argc, |
char * | argv[] | ||
) |
other signature for fParse, when argv needs to be without const due to external constraints
Definition at line 164 of file Options.cpp.
References fParse().
const std::vector< std::string > & options::parser::fParse | ( | int | argc, |
const char * | argv[] | ||
) |
parse the options on the command line
The command line is passed via the argc and argv parameres, which will reamain unchanged. Also reads config files, using fReadConfigFiles() and all files which are explicitly requested by –readCfgFile options.
Definition at line 168 of file Options.cpp.
References options::internal::conCat(), fCheckConsistency(), fComplainAndLeave(), options::internal::conversionError::fGetArgument(), options::internal::rangeError::fGetBadValue(), fGetErrorStream(), options::base::fGetLongName(), options::internal::optionError::fGetOption(), options::base::fGetOptionMap(), options::internal::positional_base::fGetPositonalArgs(), options::base::fGetShortOptionMap(), options::internal::conversionError::fGetType(), fReadConfigFiles(), options::base::fWriteRange(), options::internal::sourceFile::gCmdLine, options::internal::gOptionDebugOptions, options::internal::gOptionNoCfgFiles, lMinusMinusJustEndsOptions, lParsingIsDone, lPrimaryAssignment, lProgName, lStuffAfterMinusMinus, and lUnusedOptions.
Referenced by fParse(), and main().
|
static |
Definition at line 376 of file Options.cpp.
Referenced by options::escapedIO::operator<<().
|
protected |
Definition at line 646 of file Options.cpp.
References options::base::fGetLongName(), options::base::fIsHidden(), options::base::fWriteValue(), options::base::lExplanation, options::base::lForbiddenOptions, options::base::lLongName, options::base::lRequiredOptions, lRequiredOptions, and options::base::lShortName.
Referenced by fHelp().
void options::parser::fReadCfgFile | ( | const std::string & | aFileName, |
const options::internal::sourceItem & | aSource, | ||
bool | aMayBeAbsent = false |
||
) |
Definition at line 819 of file Options.cpp.
References options::internal::conCat(), fGetErrorStream(), options::internal::sourceItem::fGetFile(), options::base::fGetOptionMap(), fReCaptureEscapedString(), options::internal::gNoCfgFileRecursion, and lUnusedOptions.
Referenced by fReadConfigFiles(), and options::internal::OptionReadCfgFile< mayBeMissing >::fSetMe().
|
protected |
read config files if present
this function iterates over the list of config file search paths, replacing ~ by the home directory and then appends the program name to the path, and if a file is found it is then read as config file.
Definition at line 153 of file Options.cpp.
References f(), fReadCfgFile(), lProgName, and lSearchPaths.
Referenced by fParse().
|
static |
Definition at line 429 of file Options.cpp.
Referenced by fReadCfgFile().
|
virtual |
Definition at line 135 of file Options.cpp.
References lRequiredOptions.
Referenced by main().
|
virtual |
Definition at line 138 of file Options.cpp.
References lRequiredOptions.
void options::parser::fSetAssignmentChars | ( | char | aPrimary = '=' , |
char | aSecondary = ':' |
||
) |
Definition at line 127 of file Options.cpp.
References lPrimaryAssignment, and lSecondaryAssignment.
Referenced by parser().
void options::parser::fSetErrorStream | ( | std::ostream * | aStream | ) |
Definition at line 118 of file Options.cpp.
References lErrorStream.
void options::parser::fSetExecutableName | ( | const char * | aName | ) |
Definition at line 131 of file Options.cpp.
References lExecutableName.
Referenced by main().
void options::parser::fSetHelpReturnValue | ( | int | aValue | ) |
Definition at line 124 of file Options.cpp.
References lHelpReturnValue.
Referenced by main().
void options::parser::fSetMessageStream | ( | std::ostream * | aStream | ) |
Definition at line 115 of file Options.cpp.
References lMessageStream.
Referenced by main().
void options::parser::fSetMinusMinusStartsExtraList | ( | ) |
switch on use of – to separate a trailer on the command line that is not to be parsed
Definition at line 372 of file Options.cpp.
References lMinusMinusJustEndsOptions.
Referenced by main().
void options::parser::fWriteCfgFile | ( | const std::string & | aFileName | ) |
Definition at line 771 of file Options.cpp.
References options::base::fGetOptionMap(), lExecutableName, and lProgName.
Referenced by options::internal::OptionWriteCfgFile::fSetMe().
|
staticprotected |
Definition at line 365 of file Options.h.
Referenced by fGetInstance(), parser(), and ~parser().
|
protected |
|
protected |
Definition at line 376 of file Options.h.
Referenced by fGetErrorStream(), fSetErrorStream(), and parser().
|
protected |
Definition at line 378 of file Options.h.
Referenced by fSetExecutableName(), and fWriteCfgFile().
|
protected |
Definition at line 379 of file Options.h.
Referenced by fGetHelpReturnValue(), fSetHelpReturnValue(), and parser().
|
protected |
Definition at line 375 of file Options.h.
Referenced by fHelp(), fSetMessageStream(), and parser().
|
protected |
Definition at line 374 of file Options.h.
Referenced by fParse(), fSetMinusMinusStartsExtraList(), and parser().
|
protected |
Definition at line 383 of file Options.h.
Referenced by fIsParsingDone(), and fParse().
|
protected |
Definition at line 380 of file Options.h.
Referenced by fParse(), and fSetAssignmentChars().
|
protected |
Definition at line 377 of file Options.h.
Referenced by fGetProgName(), fHelp(), fParse(), fReadConfigFiles(), and fWriteCfgFile().
|
protected |
Definition at line 372 of file Options.h.
Referenced by fCheckConsistency(), fPrintOptionHelp(), and fRequire().
|
protected |
Definition at line 368 of file Options.h.
Referenced by fHelp(), and fReadConfigFiles().
|
protected |
Definition at line 381 of file Options.h.
Referenced by fGetSecondaryAssignment(), and fSetAssignmentChars().
|
protected |
Definition at line 370 of file Options.h.
Referenced by fGetStuffAfterMinusMinus(), and fParse().
|
protected |
|
protected |
Definition at line 369 of file Options.h.
Referenced by fParse(), and fReadCfgFile().