C++ Utilities 5.27.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
The HelpArgument class prints help information for an argument parser when present (–help, -h). More...
#include <argumentparser.h>
Public Member Functions | |
HelpArgument (ArgumentParser &parser) | |
Constructs a new help argument for the specified parser. | |
Public Member Functions inherited from CppUtilities::Argument | |
Argument (const char *name, char abbreviation='\0', const char *description=nullptr, const char *example=nullptr) | |
Constructs an Argument with the given name, abbreviation and description. | |
~Argument () | |
Destroys the Argument. | |
const char * | name () const |
Returns the name of the argument. | |
void | setName (const char *name) |
Sets the name of the argument. | |
char | abbreviation () const |
Returns the abbreviation of the argument. | |
void | setAbbreviation (char abbreviation) |
Sets the abbreviation of the argument. | |
const char * | environmentVariable () const |
Returns the environment variable queried when firstValue() is called. | |
void | setEnvironmentVariable (const char *environmentVariable) |
Sets the environment variable queried when firstValue() is called. | |
const char * | description () const |
Returns the description of the argument. | |
void | setDescription (const char *description) |
Sets the description of the argument. | |
const char * | example () const |
Returns the usage example of the argument. | |
void | setExample (const char *example) |
Sets the a usage example for the argument. | |
std::size_t | requiredValueCount () const |
Returns the number of values which are required to be given for this argument. | |
void | setRequiredValueCount (std::size_t requiredValueCount) |
Sets the number of values which are required to be given for this argument. | |
const std::vector< const char * > & | valueNames () const |
Returns the names of the required values. | |
void | setValueNames (std::initializer_list< const char * > valueNames) |
Sets the names of the required values. | |
void | appendValueName (const char *valueName) |
Appends a value name. | |
void | setConstraints (std::size_t minOccurrences, std::size_t maxOccurrences) |
Sets the allowed number of occurrences. | |
const std::vector< Argument * > & | path (std::size_t occurrence=0) const |
Returns the path of the specified occurrence. | |
bool | isRequired () const |
Returns an indication whether the argument is mandatory. | |
void | setRequired (bool required) |
Sets whether this argument is mandatory or not. | |
Argument::Flags | flags () const |
Returns Argument::Flags for the argument. | |
void | setFlags (Argument::Flags flags) |
Replaces all Argument::Flags for the argument with the flags. | |
void | setFlags (Argument::Flags flags, bool add) |
Adds or removes the specified flags. | |
bool | isCombinable () const |
Returns an indication whether the argument is combinable. | |
void | setCombinable (bool combinable) |
Sets whether this argument can be combined. | |
bool | isImplicit () const |
Returns an indication whether the argument is an implicit argument. | |
void | setImplicit (bool implicit) |
Sets whether the argument is an implicit argument. | |
bool | denotesOperation () const |
Returns whether the argument denotes an operation. | |
void | setDenotesOperation (bool denotesOperation) |
Sets whether the argument denotes the operation. | |
const CallbackFunction & | callback () const |
Returns the assigned callback function. | |
void | setCallback (CallbackFunction callback) |
Sets a callback function which will be called by the parser if the argument could be found and no parsing errors occurred. | |
const ArgumentVector & | subArguments () const |
Returns the secondary arguments for this argument. | |
void | setSubArguments (const ArgumentInitializerList &subArguments) |
Sets the secondary arguments for this argument. | |
void | addSubArguments (const ArgumentInitializerList &subArguments) |
Sets the secondary arguments for this argument. | |
void | addSubArgument (Argument *arg) |
Adds arg as a secondary argument for this argument. | |
bool | hasSubArguments () const |
Returns an indication whether the argument has secondary arguments. | |
const ArgumentVector & | parents () const |
Returns the parents of this argument. | |
void | printInfo (std::ostream &os, unsigned char indentation=0) const |
Writes the name, the abbreviation and other information about the Argument to the give ostream. | |
ValueCompletionBehavior | valueCompletionBehaviour () const |
Returns the items to be considered when generating completion for the values. | |
void | setValueCompletionBehavior (ValueCompletionBehavior valueCompletionBehaviour) |
Sets the items to be considered when generating completion for the values. | |
const char * | preDefinedCompletionValues () const |
Returns the assigned values used when generating completion for the values. | |
void | setPreDefinedCompletionValues (const char *preDefinedCompletionValues) |
Assigns the values to be used when generating completion for the values. | |
const std::vector< const char * > & | values (std::size_t occurrence=0) const |
Returns the parameter values for the specified occurrence of argument. | |
template<typename... TargetType> | |
std::tuple< TargetType... > | valuesAs (std::size_t occurrence=0) const |
Converts the present values for the specified occurrence to the specified target types. | |
template<typename... TargetType> | |
std::vector< std::tuple< TargetType... > > | allValuesAs () const |
Converts the present values for all occurrence to the specified target types. | |
const char * | firstValue () const |
Returns the first parameter value of the first occurrence of the argument. | |
const char * | firstValueOr (const char *fallback) const |
Returns the first value like Argument::firstValue() but returns fallback instead of nullptr if there's no value. | |
bool | allRequiredValuesPresent (std::size_t occurrence=0) const |
Returns an indication whether all required values are present. | |
bool | isPresent () const |
Returns an indication whether the argument could be detected when parsing. | |
std::size_t | occurrences () const |
Returns how often the argument could be detected when parsing. | |
std::size_t | index (std::size_t occurrence) const |
Returns the indices of the argument's occurrences which could be detected when parsing. | |
std::size_t | minOccurrences () const |
Returns the minimum number of occurrences. | |
std::size_t | maxOccurrences () const |
Returns the maximum number of occurrences. | |
bool | isDeprecated () const |
const Argument * | deprecatedBy () const |
Returns the argument which obsoletes this argument. | |
void | markAsDeprecated (const Argument *deprecatedBy=nullptr) |
Marks the argument as deprecated. | |
bool | isMainArgument () const |
Returns an indication whether the argument is used as main argument. | |
bool | isParentPresent () const |
Returns whether at least one parent argument is present. | |
Argument * | conflictsWithArgument () const |
Checks if this arguments conflicts with other arguments. | |
Argument * | wouldConflictWithArgument () const |
Checks if this argument would conflict with other arguments if it was present. | |
Argument * | specifiedOperation () const |
Returns the first operation argument specified by the user or nullptr if no operation has been specified. | |
const std::vector< ArgumentOccurrence > & | occurrenceInfo () const |
Returns information about all occurrences of the argument which have been detected when parsing. | |
std::vector< ArgumentOccurrence > & | occurrenceInfo () |
Returns information about all occurrences of the argument which have been detected when parsing. | |
void | reset () |
Resets occurrences (indices, values and paths). | |
void | resetRecursively () |
Resets this argument and all sub arguments recursively. | |
Additional Inherited Members | |
Public Types inherited from CppUtilities::Argument | |
enum class | Flags : std::uint64_t { None = 0x0 , Combinable = 0x1 , Implicit = 0x2 , Operation = 0x4 , Deprecated = 0x8 , Greedy = 0x10 } |
The Flags enum specifies options for treating the argument in a special way. More... | |
typedef std::function< void(const ArgumentOccurrence &)> | CallbackFunction |
Static Public Attributes inherited from CppUtilities::Argument | |
static constexpr std::size_t | varValueCount = std::numeric_limits<std::size_t>::max() |
Denotes a variable number of values. | |
The HelpArgument class prints help information for an argument parser when present (–help, -h).
Definition at line 431 of file argumentparser.h.
CppUtilities::HelpArgument::HelpArgument | ( | ArgumentParser & | parser | ) |
Constructs a new help argument for the specified parser.
Definition at line 1718 of file argumentparser.cpp.