args-parser 6.3.6
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
CommandsetRequired (bool on=true) override
 Set required flag.
const StringvalueSpecifier () const override
CommandsetValueSpecifier (const String &vs)
 Set value specifier.
const Stringdescription () const override
CommandsetDescription (const String &desc)
 Set description.
const StringlongDescription () const override
CommandsetLongDescription (const String &desc)
 Set long description.
const Stringvalue () const
const StringListvalues () const
const StringdefaultValue () const override
CommandsetDefaultValue (const String &v)
 Set default value.
const StringListdefaultValues () const
CommandsetDefaultValues (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.
CommandaddArg (ArgPtr arg) override
 Add argument.
GroupIfaceaddArg (ArgIface &arg)
 Add argument.
GroupIfaceaddArg (ArgIface *arg)
 Add argument.
Public Member Functions inherited from Args::GroupIface
template<typename T>
 GroupIface (T &&name, bool required=false)
virtual ~GroupIface ()
const Argumentschildren () const
GroupIfaceaddArg (ArgIface &arg)
 Add argument.
GroupIfaceaddArg (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 27 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 35 of file command.hpp.

◆ ~Command()

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

Definition at line 69 of file command.hpp.

Member Function Documentation

◆ addArg() [1/3]

Add argument.

Note
Developer should handle lifetime of the argument.

Definition at line 60 of file group_iface.hpp.

◆ addArg() [2/3]

Add argument.

Note
Developer should handle lifetime of the argument.

Definition at line 66 of file group_iface.hpp.

◆ addArg() [3/3]

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

Add argument.

Reimplemented from Args::GroupIface.

Definition at line 242 of file command.hpp.

◆ checkCorrectnessAfterParsing()

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

Check correctness of the argument after parsing.

Implements Args::ArgIface.

Definition at line 373 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 345 of file command.hpp.

◆ clear()

void Args::Command::clear ( )
inlineoverridevirtual

Clear state of the argument.

Implements Args::ArgIface.

Definition at line 230 of file command.hpp.

◆ defaultValue()

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

Reimplemented from Args::ArgIface.

Definition at line 161 of file command.hpp.

◆ defaultValues()

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

Definition at line 179 of file command.hpp.

◆ description()

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

Implements Args::ArgIface.

Definition at line 111 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 268 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 292 of file command.hpp.

◆ isDefined()

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

Implements Args::ArgIface.

Definition at line 80 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 214 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 192 of file command.hpp.

◆ isWithValue()

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

Implements Args::ArgIface.

Definition at line 86 of file command.hpp.

◆ longDescription()

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

Implements Args::ArgIface.

Definition at line 123 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 313 of file command.hpp.

◆ setCurrentSubCommand()

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

Set current subcommand.

Definition at line 385 of file command.hpp.

◆ setDefaultValue()

Command & 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 172 of file command.hpp.

◆ setDefaultValues()

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

Set default values.

Definition at line 185 of file command.hpp.

◆ setDescription()

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

Set description.

Definition at line 116 of file command.hpp.

◆ setLongDescription()

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

Set long description.

Definition at line 132 of file command.hpp.

◆ setRequired()

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

Set required flag.

Reimplemented from Args::GroupIface.

Definition at line 92 of file command.hpp.

◆ setValueSpecifier()

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

Set value specifier.

Definition at line 104 of file command.hpp.

◆ type()

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

Implements Args::ArgIface.

Definition at line 74 of file command.hpp.

◆ value()

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

Definition at line 139 of file command.hpp.

◆ values()

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

Definition at line 151 of file command.hpp.

◆ valueSpecifier()

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

Implements Args::ArgIface.

Definition at line 99 of file command.hpp.

◆ CmdLine

friend class CmdLine
friend

Definition at line 29 of file command.hpp.

◆ Help

friend class Help
friend

Definition at line 31 of file command.hpp.

◆ HelpPrinter

friend class HelpPrinter
friend

Definition at line 30 of file command.hpp.


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