args-parser 6.3.3
Loading...
Searching...
No Matches
Args::CmdLine Class Referencefinal

CmdLine is class that holds all rguments and parse command line arguments in the correspondence with holded arguments. More...

#include <cmd_line.hpp>

+ Inheritance diagram for Args::CmdLine:
+ Collaboration diagram for Args::CmdLine:

Public Types

enum  CmdLineOpt { Empty = 0 , CommandIsRequired = 1 , HandlePositionalArguments = 2 }
 Command line options. More...
 
using ArgPtr = ArgPtrToAPI
 Smart pointer to the argument.
 
using Arguments = std::vector< ArgPtr >
 List of child arguments.
 
using CmdLineOpts = int
 Storage of command line options.
 

Public Member Functions

 CmdLine (CmdLineOpts opt=Empty)
 Construct empty CmdLine.
 
 CmdLine (int argc, const char *const *argv, CmdLineOpts opt=Empty)
 Construct CmdLine with set command line arguments.
 
virtual ~CmdLine ()
 
CmdLineOpts parserOptions () const
 
void addArg (ArgIface *arg)
 Add argument.
 
void addArg (ArgIface &arg)
 Add argument.
 
void addArg (ArgPtr arg)
 Add argument.
 
void parse ()
 Parse arguments.
 
void parse (int argc, const char *const *argv)
 Parse arguments.
 
const StringListpositional () const
 
const StringpositionalDescription () const
 
void setPositionalDescription (const String &d)
 Set positional string description for the help.
 
ArgIfacefindArgument (const String &name)
 
const ArgIfacefindArgument (const String &name) const
 
const Argumentsarguments () const
 
bool isMisspelledName (const String &name, StringList &possibleNames) const
 
CmdLineaddHelp (bool throwExceptionOnPrint=true, const String &appExe=String(), const String &appDesc=String(), String::size_type length=79, const String &posDesc=String())
 Add help.
 
template<typename T >
void addHelp (T throwExceptionOnPrint, const String &appExe=String(), const String &appDesc=String(), String::size_type length=79)=delete
 
String value (const String &name) const
 
StringList values (const String &name) const
 
bool isDefined (const String &name) const
 
void clear ()
 Clear state of the arguments.
 
- Public Member Functions inherited from Args::details::API< PARENT, SELF, ARGPTR, true >
 API (PARENT &parent, SELF &self)
 
virtual ~API ()
 
template<typename NAME >
API< PARENT, OnlyOneGroup, ARGPTR, falseaddOnlyOneGroup (NAME &&name, bool required=false)
 Add OnlyOneGroup.
 
template<typename NAME >
API< PARENT, AllOfGroup, ARGPTR, falseaddAllOfGroup (NAME &&name, bool required=false)
 Add AllOfGroup.
 
template<typename NAME >
API< PARENT, AtLeastOneGroup, ARGPTR, falseaddAtLeastOneGroup (NAME &&name, bool required=false)
 Add AtLeastOneGroup.
 
template<typename NAME >
PARENTaddArgWithFlagAndName (Char flag, NAME &&name, bool isWithValue=false, bool isRequired=false, const String &desc=String(), const String &longDesc=String(), const String &defaultValue=String(), const String &valueSpecifier=String())
 Add argument.
 
PARENTaddArgWithFlagOnly (Char flag, bool isWithValue=false, bool isRequired=false, const String &desc=String(), const String &longDesc=String(), const String &defaultValue=String(), const String &valueSpecifier=String())
 Add argument with flag only.
 
template<typename NAME >
PARENTaddArgWithNameOnly (NAME &&name, bool isWithValue=false, bool isRequired=false, const String &desc=String(), const String &longDesc=String(), const String &defaultValue=String(), const String &valueSpecifier=String())
 Add argument with name only.
 
template<typename NAME >
PARENTaddMultiArg (Char flag, NAME &&name, bool isWithValue=false, bool isRequired=false, const String &desc=String(), const String &longDesc=String(), const String &defaultValue=String(), const String &valueSpecifier=String())
 Add multi argument.
 
PARENTaddMultiArgWithFlagOnly (Char flag, bool isWithValue=false, bool isRequired=false, const String &desc=String(), const String &longDesc=String(), const String &defaultValue=String(), const String &valueSpecifier=String())
 Add multi argument with flag only.
 
template<typename NAME >
PARENTaddMultiArgWithNameOnly (NAME &&name, bool isWithValue=false, bool isRequired=false, const String &desc=String(), const String &longDesc=String(), const String &defaultValue=String(), const String &valueSpecifier=String())
 Add multi argument with name only.
 
template<typename NAME >
PARENTaddMultiArgWithDefaulValues (Char flag, NAME &&name, bool isWithValue=false, bool isRequired=false, const String &desc=String(), const String &longDesc=String(), const StringList &defaultValues=StringList(), const String &valueSpecifier=String())
 Add multi argument.
 
PARENTaddMultiArgWithFlagOnlyAndDefaultValues (Char flag, bool isWithValue=false, bool isRequired=false, const String &desc=String(), const String &longDesc=String(), const StringList &defaultValues=StringList(), const String &valueSpecifier=String())
 Add multi argument with flag only.
 
template<typename NAME >
PARENTaddMultiArgWithNameOnlyAndDefaultValues (NAME &&name, bool isWithValue=false, bool isRequired=false, const String &desc=String(), const String &longDesc=String(), const StringList &defaultValues=StringList(), const String &valueSpecifier=String())
 Add multi argument with name only.
 
template<typename NAME >
API< PARENT, Command, ARGPTR, falseaddCommand (NAME &&name, ValueOptions opt=ValueOptions::NoValue, bool isSubCommandRequired=false, const String &desc=String(), const String &longDesc=String(), const String &defaultValue=String(), const String &valueSpecifier=String())
 Add Command.
 
template<typename NAME >
API< PARENT, Command, ARGPTR, falseaddCommandWithDefaultValues (NAME &&name, ValueOptions opt=ValueOptions::NoValue, bool isSubCommandRequired=false, const String &desc=String(), const String &longDesc=String(), const StringList &defaultValues=StringList(), const String &valueSpecifier=String())
 Add Command.
 

Detailed Description

CmdLine is class that holds all rguments and parse command line arguments in the correspondence with holded arguments.

Definition at line 121 of file cmd_line.hpp.

Member Typedef Documentation

◆ ArgPtr

Smart pointer to the argument.

Definition at line 126 of file cmd_line.hpp.

◆ Arguments

using Args::CmdLine::Arguments = std::vector< ArgPtr >

List of child arguments.

Definition at line 128 of file cmd_line.hpp.

◆ CmdLineOpts

Storage of command line options.

Definition at line 141 of file cmd_line.hpp.

Member Enumeration Documentation

◆ CmdLineOpt

Command line options.

Enumerator
Empty 

No special options.

CommandIsRequired 

Command should be defined.

HandlePositionalArguments 

Handle positional arguments.

Definition at line 131 of file cmd_line.hpp.

Constructor & Destructor Documentation

◆ CmdLine() [1/2]

Args::CmdLine::CmdLine ( CmdLineOpts  opt = Empty)
inlineexplicit

Construct empty CmdLine.

Definition at line 144 of file cmd_line.hpp.

◆ CmdLine() [2/2]

Args::CmdLine::CmdLine ( int  argc,
const char *const *  argv,
CmdLineOpts  opt = Empty 
)
inline

Construct CmdLine with set command line arguments.

Definition at line 524 of file cmd_line.hpp.

◆ ~CmdLine()

virtual Args::CmdLine::~CmdLine ( )
inlinevirtual

Definition at line 162 of file cmd_line.hpp.

Member Function Documentation

◆ addArg() [1/3]

void Args::CmdLine::addArg ( ArgIface arg)
inline

Add argument.

Note
Developer should handle lifetime of the argument.

Definition at line 558 of file cmd_line.hpp.

◆ addArg() [2/3]

void Args::CmdLine::addArg ( ArgIface arg)
inline

Add argument.

Note
Developer should handle lifetime of the argument.

Definition at line 535 of file cmd_line.hpp.

◆ addArg() [3/3]

void Args::CmdLine::addArg ( ArgPtr  arg)
inline

Add argument.

Definition at line 179 of file cmd_line.hpp.

◆ addHelp() [1/2]

CmdLine & Args::CmdLine::addHelp ( bool  throwExceptionOnPrint = true,
const String appExe = String(),
const String appDesc = String(),
String::size_type  length = 79,
const String posDesc = String() 
)
inline

Add help.

Parameters
throwExceptionOnPrintShould exception be thrown on help printing.
appExeApplication executable.
appDescApplication description.
lengthLine length.
posDescPositional string in the help.

Definition at line 319 of file cmd_line.hpp.

◆ addHelp() [2/2]

template<typename T >
void Args::CmdLine::addHelp ( throwExceptionOnPrint,
const String appExe = String(),
const String appDesc = String(),
String::size_type  length = 79 
)
delete

◆ arguments()

const CmdLine::Arguments & Args::CmdLine::arguments ( ) const
inline
Returns
All arguments.

Definition at line 761 of file cmd_line.hpp.

◆ clear()

void Args::CmdLine::clear ( )
inline

Clear state of the arguments.

Definition at line 435 of file cmd_line.hpp.

◆ findArgument() [1/2]

ArgIface * Args::CmdLine::findArgument ( const String name)
inline
Returns
Argument for the given name.
Note
It's impossible to find any GroupIface with exception of Command.

Definition at line 229 of file cmd_line.hpp.

◆ findArgument() [2/2]

const ArgIface * Args::CmdLine::findArgument ( const String name) const
inline
Returns
Argument for the given name.
Note
It's impossible to find any GroupIface with exception of Command.

Definition at line 258 of file cmd_line.hpp.

◆ isDefined()

bool Args::CmdLine::isDefined ( const String name) const
inline
Returns
Is argument defined?
Note
It's impossible to check if any GroupIface is defined with exception of Command.
Parameters
nameName of the argument. Should be full name, i.e '-a' or '–arg' or 'add' if it's a command or subcommand.

Definition at line 421 of file cmd_line.hpp.

◆ isMisspelledName()

bool Args::CmdLine::isMisspelledName ( const String name,
StringList possibleNames 
) const
inline
Returns
Is given name a misspelled name of the argument.
Parameters
nameName to check (misspelled).
possibleNamesList of possible names for the given misspelled name.

Definition at line 289 of file cmd_line.hpp.

◆ parse() [1/2]

void Args::CmdLine::parse ( )
inline

Parse arguments.

Definition at line 564 of file cmd_line.hpp.

◆ parse() [2/2]

void Args::CmdLine::parse ( int  argc,
const char *const *  argv 
)
inline

Parse arguments.

Definition at line 201 of file cmd_line.hpp.

◆ parserOptions()

CmdLineOpts Args::CmdLine::parserOptions ( ) const
inline
Returns
Parser options.

Definition at line 167 of file cmd_line.hpp.

◆ positional()

const StringList & Args::CmdLine::positional ( ) const
inline
Returns
Positional arguments.

Definition at line 210 of file cmd_line.hpp.

◆ positionalDescription()

const String & Args::CmdLine::positionalDescription ( ) const
inline
Returns
Positional string description for the help.

Definition at line 216 of file cmd_line.hpp.

◆ setPositionalDescription()

void Args::CmdLine::setPositionalDescription ( const String d)
inline

Set positional string description for the help.

Definition at line 222 of file cmd_line.hpp.

◆ value()

String Args::CmdLine::value ( const String name) const
inline
Returns
Value of the argument.
Parameters
nameName of the argument. Should be full name, i.e '-a' or '–arg' or 'add' if it's a command or subcommand.

Definition at line 360 of file cmd_line.hpp.

◆ values()

StringList Args::CmdLine::values ( const String name) const
inline
Returns
Values of the argument.
Parameters
nameName of the argument. Should be full name, i.e '-a' or '–arg' or 'add' if it's a command or subcommand.

Definition at line 389 of file cmd_line.hpp.


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