args-parser 6.3.6
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
CmdLineaddArg (ArgIface *arg)
 Add argument.
CmdLineaddArg (ArgIface &arg)
 Add argument.
CmdLineaddArg (ArgPtr arg)
 Add argument.
void parse ()
 Parse arguments.
void parse (int argc, const char *const *argv)
 Parse arguments.
const StringListpositional () const
const StringpositionalDescription () const
CmdLinesetPositionalDescription (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, false > addOnlyOneGroup (NAME &&name, bool required=false)
 Add OnlyOneGroup.
template<typename NAME>
API< PARENT, AllOfGroup, ARGPTR, false > addAllOfGroup (NAME &&name, bool required=false)
 Add AllOfGroup.
template<typename NAME>
API< PARENT, AtLeastOneGroup, ARGPTR, false > addAtLeastOneGroup (NAME &&name, bool required=false)
 Add AtLeastOneGroup.
template<typename NAME>
PARENT & addArgWithFlagAndName (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.
PARENT & addArgWithFlagOnly (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>
PARENT & addArgWithNameOnly (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>
PARENT & addMultiArg (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.
PARENT & addMultiArgWithFlagOnly (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>
PARENT & addMultiArgWithNameOnly (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>
PARENT & addMultiArgWithDefaulValues (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.
PARENT & addMultiArgWithFlagOnlyAndDefaultValues (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>
PARENT & addMultiArgWithNameOnlyAndDefaultValues (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, false > addCommand (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, false > addCommandWithDefaultValues (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 97 of file cmd_line.hpp.

Member Typedef Documentation

◆ ArgPtr

Smart pointer to the argument.

Definition at line 101 of file cmd_line.hpp.

◆ Arguments

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

List of child arguments.

Definition at line 103 of file cmd_line.hpp.

◆ CmdLineOpts

Storage of command line options.

Definition at line 116 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 106 of file cmd_line.hpp.

Constructor & Destructor Documentation

◆ CmdLine() [1/2]

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

Construct empty CmdLine.

Definition at line 119 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 495 of file cmd_line.hpp.

◆ ~CmdLine()

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

Definition at line 143 of file cmd_line.hpp.

Member Function Documentation

◆ addArg() [1/3]

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

Add argument.

Note
Developer should handle lifetime of the argument.

Definition at line 530 of file cmd_line.hpp.

◆ addArg() [2/3]

CmdLine & Args::CmdLine::addArg ( ArgIface * arg)
inline

Add argument.

Note
Developer should handle lifetime of the argument.

Definition at line 512 of file cmd_line.hpp.

◆ addArg() [3/3]

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

Add argument.

Definition at line 160 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 292 of file cmd_line.hpp.

◆ addHelp() [2/2]

template<typename T>
void Args::CmdLine::addHelp ( T 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 721 of file cmd_line.hpp.

◆ clear()

void Args::CmdLine::clear ( )
inline

Clear state of the arguments.

Definition at line 406 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 211 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 238 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 391 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 267 of file cmd_line.hpp.

◆ parse() [1/2]

void Args::CmdLine::parse ( )
inline

Parse arguments.

Definition at line 535 of file cmd_line.hpp.

◆ parse() [2/2]

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

Parse arguments.

Definition at line 181 of file cmd_line.hpp.

◆ parserOptions()

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

Definition at line 148 of file cmd_line.hpp.

◆ positional()

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

Definition at line 191 of file cmd_line.hpp.

◆ positionalDescription()

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

Definition at line 197 of file cmd_line.hpp.

◆ setPositionalDescription()

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

Set positional string description for the help.

Definition at line 203 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 335 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 362 of file cmd_line.hpp.


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