args-parser 6.3.3
Loading...
Searching...
No Matches
Args::Command Class Reference

Command in the command line interface. More...

#include <command.hpp>

+ Inheritance diagram for Args::Command:
+ Collaboration diagram for Args::Command:

Public Member Functions

template<typename T >
 Command (T &&nm, ValueOptions opt=ValueOptions::NoValue, bool isSubCommandRequired=false)
 
virtual ~Command ()
 
ArgType type () const override
 
bool isDefined () const override
 
bool isWithValue () const override
 
void setRequired (bool on=true) override
 Set required flag.
 
const StringvalueSpecifier () const override
 
void setValueSpecifier (const String &vs)
 Set value specifier.
 
const Stringdescription () const override
 
void setDescription (const String &desc)
 Set description.
 
const StringlongDescription () const override
 
void setLongDescription (const String &desc)
 Set long description.
 
const Stringvalue () const
 
const StringListvalues () const
 
const StringdefaultValue () const
 
void setDefaultValue (const String &v)
 
const StringListdefaultValues () const
 
void setDefaultValues (const StringList &v)
 Set default values.
 
bool isMisspelledName (const String &nm, StringList &possibleNames) const override
 
bool isMisspelledCommand (const String &nm, StringList &possibleNames) const
 
void clear () override
 Clear state of the argument.
 
void addArg (ArgPtr arg) override
 Add argument.
 
void addArg (ArgIface &arg)
 Add argument.
 
void addArg (ArgIface *arg)
 Add argument.
 
virtual void addArg (ArgPtr arg)
 Add argument.
 
- Public Member Functions inherited from Args::GroupIface
template<typename T >
 GroupIface (T &&name, bool required=false)
 
virtual ~GroupIface ()
 
const Argumentschildren () const
 
void addArg (ArgIface &arg)
 Add argument.
 
void addArg (ArgIface *arg)
 Add argument.
 
String name () const override
 
bool isWithValue () const override
 
bool isRequired () const override
 
const Stringflag () const override
 
const StringargumentName () const override
 
const StringvalueSpecifier () const override
 
const Stringdescription () const override
 
const StringlongDescription () const override
 
void clear () override
 Clear state of the argument.
 
- Public Member Functions inherited from Args::ArgIface
 ArgIface ()
 
virtual ~ArgIface ()
 
CmdLinecmdLine () const
 

Protected Member Functions

ArgIfacefindArgument (const String &n) override
 
ArgIfacefindChild (const String &name)
 
void process (Context &ctx) override
 Process argument's staff, for example take values from context.
 
void checkCorrectnessBeforeParsing (StringList &flags, StringList &names) const override
 Check correctness of the argument before parsing.
 
void checkCorrectnessAfterParsing () const override
 Check correctness of the argument after parsing.
 
void setCurrentSubCommand (Command *sub)
 Set current subcommand.
 
- Protected Member Functions inherited from Args::GroupIface
ArgIfacefindArgument (const String &name) override
 
void process (Context &) override
 Process argument's staff, for example take values from context.
 
void checkCorrectnessBeforeParsing (StringList &flags, StringList &names) const override
 Check correctness of the argument before parsing.
 
void checkCorrectnessAfterParsing () const override
 Check correctness of the argument after parsing.
 
void setCmdLine (CmdLine *cmdLine) override
 Set command line parser.
 
bool isMisspelledName (const String &name, StringList &possibleNames) const override
 

Friends

class CmdLine
 
class HelpPrinter
 
class Help
 

Additional Inherited Members

- Public Types inherited from Args::GroupIface
using ArgPtr = std::unique_ptr< ArgIface, details::Deleter< ArgIface > >
 Smart pointer to the argument.
 
using Arguments = std::vector< ArgPtr >
 List of child arguments.
 
- Protected Attributes inherited from Args::GroupIface
Arguments m_children
 List of children.
 

Detailed Description

Command in the command line interface.

Definition at line 51 of file command.hpp.

Constructor & Destructor Documentation

◆ Command()

template<typename T >
Args::Command::Command ( T &&  nm,
ValueOptions  opt = ValueOptions::NoValue,
bool  isSubCommandRequired = false 
)
inlineexplicit

Definition at line 60 of file command.hpp.

◆ ~Command()

virtual Args::Command::~Command ( )
inlinevirtual

Definition at line 97 of file command.hpp.

Member Function Documentation

◆ addArg() [1/4]

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

Add argument.

Note
Developer should handle lifetime of the argument.

Definition at line 87 of file group_iface.hpp.

◆ addArg() [2/4]

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

Add argument.

Note
Developer should handle lifetime of the argument.

Definition at line 93 of file group_iface.hpp.

◆ addArg() [3/4]

virtual void Args::GroupIface::addArg ( ArgPtr  arg)
inlinevirtual

Add argument.

Reimplemented from Args::GroupIface.

Definition at line 99 of file group_iface.hpp.

◆ addArg() [4/4]

void Args::Command::addArg ( ArgPtr  arg)
inlineoverridevirtual

Add argument.

Reimplemented from Args::GroupIface.

Definition at line 262 of file command.hpp.

◆ checkCorrectnessAfterParsing()

void Args::Command::checkCorrectnessAfterParsing ( ) const
inlineoverrideprotectedvirtual

Check correctness of the argument after parsing.

Implements Args::ArgIface.

Definition at line 393 of file command.hpp.

◆ checkCorrectnessBeforeParsing()

void Args::Command::checkCorrectnessBeforeParsing ( StringList flags,
StringList names 
) const
inlineoverrideprotectedvirtual

Check correctness of the argument before parsing.

Implementation of this method must add his flag and name to the flags and names.

Parameters
flagsAll known flags.
namesAll known names.

Implements Args::ArgIface.

Definition at line 366 of file command.hpp.

◆ clear()

void Args::Command::clear ( )
inlineoverridevirtual

Clear state of the argument.

Implements Args::ArgIface.

Definition at line 250 of file command.hpp.

◆ defaultValue()

const String & Args::Command::defaultValue ( ) const
inline
Returns
Default value.

Definition at line 183 of file command.hpp.

◆ defaultValues()

const StringList & Args::Command::defaultValues ( ) const
inline
Returns
Default values.

Definition at line 199 of file command.hpp.

◆ description()

const String & Args::Command::description ( ) const
inlineoverridevirtual
Returns
Description of the argument.

Implements Args::ArgIface.

Definition at line 138 of file command.hpp.

◆ findArgument()

ArgIface * Args::Command::findArgument ( const String n)
inlineoverrideprotectedvirtual
Returns
Argument for the given name.
Return values
thisif the given name is the name of the command.
Note
Doesn't look in the children.
Parameters
nName of the argument. Can be for example "-t" or "--timeout".

Implements Args::ArgIface.

Definition at line 286 of file command.hpp.

◆ findChild()

ArgIface * Args::Command::findChild ( const String name)
inlineprotected
Returns
Argument for the given name.
Return values
Pointerto the ArgIface if this argument handles argument with the given name.
nullptrif this argument doesn't know about argument with name.
Note
Looks only in children.
Parameters
nameName of the argument. Can be for example "-t" or "--timeout".

Definition at line 309 of file command.hpp.

◆ isDefined()

bool Args::Command::isDefined ( ) const
inlineoverridevirtual
Returns
Is this command defined?

Implements Args::ArgIface.

Definition at line 108 of file command.hpp.

◆ isMisspelledCommand()

bool Args::Command::isMisspelledCommand ( const String nm,
StringList possibleNames 
) const
inline
Returns
Is given name a misspelled name of the command.
Parameters
nmName to check (misspelled).
possibleNamesList of possible names for the given misspelled name.

Definition at line 233 of file command.hpp.

◆ isMisspelledName()

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

Implements Args::ArgIface.

Definition at line 211 of file command.hpp.

◆ isWithValue()

bool Args::Command::isWithValue ( ) const
inlineoverridevirtual
Returns
Is this argument with value?

Implements Args::ArgIface.

Definition at line 114 of file command.hpp.

◆ longDescription()

const String & Args::Command::longDescription ( ) const
inlineoverridevirtual
Returns
Long description of the argument.

Implements Args::ArgIface.

Definition at line 149 of file command.hpp.

◆ process()

void Args::Command::process ( Context ctx)
inlineoverrideprotectedvirtual

Process argument's staff, for example take values from context.

This method invokes exactly at that moment when parser has found this argument.

Parameters
ctxContext of the command line.

Implements Args::ArgIface.

Definition at line 329 of file command.hpp.

◆ setCurrentSubCommand()

void Args::Command::setCurrentSubCommand ( Command sub)
inlineprotected

Set current subcommand.

Definition at line 404 of file command.hpp.

◆ setDefaultValue()

void Args::Command::setDefaultValue ( const String v)
inline

Set default value.

Note
Value will be pushed back to the list of default values.

Definition at line 193 of file command.hpp.

◆ setDefaultValues()

void Args::Command::setDefaultValues ( const StringList v)
inline

Set default values.

Definition at line 205 of file command.hpp.

◆ setDescription()

void Args::Command::setDescription ( const String desc)
inline

Set description.

Definition at line 143 of file command.hpp.

◆ setLongDescription()

void Args::Command::setLongDescription ( const String desc)
inline

Set long description.

Definition at line 157 of file command.hpp.

◆ setRequired()

void Args::Command::setRequired ( bool  on = true)
inlineoverridevirtual

Set required flag.

Reimplemented from Args::GroupIface.

Definition at line 121 of file command.hpp.

◆ setValueSpecifier()

void Args::Command::setValueSpecifier ( const String vs)
inline

Set value specifier.

Definition at line 132 of file command.hpp.

◆ type()

ArgType Args::Command::type ( ) const
inlineoverridevirtual
Returns
Type of the argument.

Implements Args::ArgIface.

Definition at line 102 of file command.hpp.

◆ value()

const String & Args::Command::value ( ) const
inline
Returns
First value of this argument.

Definition at line 163 of file command.hpp.

◆ values()

const StringList & Args::Command::values ( ) const
inline
Returns
All values for this argument.

Definition at line 174 of file command.hpp.

◆ valueSpecifier()

const String & Args::Command::valueSpecifier ( ) const
inlineoverridevirtual
Returns
Value specifier.

Implements Args::ArgIface.

Definition at line 127 of file command.hpp.

Friends And Related Symbol Documentation

◆ CmdLine

friend class CmdLine
friend

Definition at line 54 of file command.hpp.

◆ Help

friend class Help
friend

Definition at line 56 of file command.hpp.

◆ HelpPrinter

friend class HelpPrinter
friend

Definition at line 55 of file command.hpp.


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