CARDS 2.4.87
Package manager for the NuTyX GNU/Linux distribution
ArgParser Class Reference

argument parser class More...

#include <argument_parser.h>

Inheritance diagram for ArgParser:
CardsArgumentParser

Classes

class  APCmd
 
class  APOpt
 

Public Types

enum  ArgNumberCheck { NONE, MIN, EQ, MAX }
 

Public Member Functions

int addCommand (APCmd &cmd, const std::string &name, const std::string &shortInfo, const std::string &description, ArgNumberCheck argNumberCheck, const int argNumber=-1, const std::string &otherArguments="")
 
int addOption (const APCmd &cmd, APOpt &key, bool required)
 
void parse (int argc, char **argv)
 
APCmd command () const
 
std::string appName () const
 
bool isSet (const APOpt &key) const
 
std::string getOptionValue (const APOpt &key) const
 
const std::vector< std::string > & otherArguments () const
 
virtual std::string getAppIdentification () const
 
void printHelp (const std::string &cmd)
 

Detailed Description

argument parser class

Yet another argument parser, meant to speed up development of new applications. Its focus is on being object oriented and safe to use

Member Enumeration Documentation

◆ ArgNumberCheck

types of argument number checking

Member Function Documentation

◆ addCommand()

int ArgParser::addCommand ( APCmd cmd,
const std::string &  name,
const std::string &  shortInfo,
const std::string &  description,
ArgNumberCheck  argNumberCheck,
const int  argNumber = -1,
const std::string &  otherArguments = "" 
)

add a command

Parameters
cmda reference to the command; use it to compare the actually selected command against this one after parsing
namethe name of the command to be parsed from the command line
shortInfoa short description, used for general help screen
descriptiona description, used for the help screens
argNumberCheckwhat kind of argument number checking
argNumberoptional number of arguments
otherArgumentsvalue to display in the help screen for following (non option) arguments

◆ addOption()

int ArgParser::addOption ( const APCmd cmd,
APOpt key,
bool  required 
)

add an option to a command - this will fail with an assertion of key has not been initialized using init()

Parameters
cmdthe command to add an option to
keythe option reference; use it to check for certain options after parsing
requiredwhether this option is required

◆ appName()

std::string ArgParser::appName ( ) const

the name of the application, from argv[0]

◆ command()

ArgParser::APCmd ArgParser::command ( ) const

the command which was parsed, to be used to compare against actual APCmd obtained from addCommand calls

◆ getAppIdentification()

virtual std::string ArgParser::getAppIdentification ( ) const
inlinevirtual
Returns
an application identification to be used in the usage

Reimplemented in CardsArgumentParser.

◆ getOptionValue()

std::string ArgParser::getOptionValue ( const APOpt key) const
Returns
the value attached to the option
Parameters
keyif any

◆ isSet()

bool ArgParser::isSet ( const APOpt key) const
Returns
true if
Parameters
keyis set, false otherwise

◆ otherArguments()

const std::vector< std::string > & ArgParser::otherArguments ( ) const

the remaining arguments

◆ parse()

void ArgParser::parse ( int  argc,
char **  argv 
)

the actual parsing. Highly recommended :-)

◆ printHelp()

void ArgParser::printHelp ( const std::string &  cmd)
Returns
the help of the command

The documentation for this class was generated from the following files: