nfd::tools::nfdc::CommandDefinition Class Reference

Defines a command. More...

#include <tools/nfdc/command-definition.hpp>

Classes

class  Error
 

Public Member Functions

 CommandDefinition (std::string_view noun, std::string_view verb)
 
 ~CommandDefinition ()
 
CommandDefinitionaddArg (const std::string &name, ArgValueType valueType, Required isRequired=Required::NO, Positional allowPositional=Positional::NO, const std::string &metavar="")
 Declare an argument. More...
 
const std::string & getNoun () const
 
const std::string & getTitle () const
 
const std::string & getVerb () const
 
CommandArguments parse (const std::vector< std::string > &tokens, size_t start=0) const
 Parse a command line. More...
 
CommandDefinitionsetTitle (std::string_view title)
 Set one-line description. More...
 

Detailed Description

Defines a command.

Definition at line 126 of file command-definition.hpp.

Constructor & Destructor Documentation

◆ CommandDefinition()

nfd::tools::nfdc::CommandDefinition::CommandDefinition ( std::string_view  noun,
std::string_view  verb 
)

Definition at line 96 of file command-definition.cpp.

◆ ~CommandDefinition()

nfd::tools::nfdc::CommandDefinition::~CommandDefinition ( )
default

Member Function Documentation

◆ addArg()

CommandDefinition & nfd::tools::nfdc::CommandDefinition::addArg ( const std::string &  name,
ArgValueType  valueType,
Required  isRequired = Required::NO,
Positional  allowPositional = Positional::NO,
const std::string &  metavar = "" 
)

Declare an argument.

Parameters
nameargument name, must be unique
valueTypeargument value type
isRequiredwhether the argument is required
allowPositionalwhether the argument value can be specified as positional
metavardisplayed argument value placeholder

Definition at line 105 of file command-definition.cpp.

◆ getNoun()

const std::string& nfd::tools::nfdc::CommandDefinition::getNoun ( ) const
inline

Definition at line 140 of file command-definition.hpp.

◆ getTitle()

const std::string& nfd::tools::nfdc::CommandDefinition::getTitle ( ) const
inline
Returns
one-line description

Definition at line 155 of file command-definition.hpp.

◆ getVerb()

const std::string& nfd::tools::nfdc::CommandDefinition::getVerb ( ) const
inline

Definition at line 146 of file command-definition.hpp.

◆ parse()

CommandArguments nfd::tools::nfdc::CommandDefinition::parse ( const std::vector< std::string > &  tokens,
size_t  start = 0 
) const

Parse a command line.

Parameters
tokenscommand line tokens
startcommand line start position, after noun and verb
Exceptions
Errorcommand line is invalid

Definition at line 130 of file command-definition.cpp.

◆ setTitle()

CommandDefinition& nfd::tools::nfdc::CommandDefinition::setTitle ( std::string_view  title)
inline

Set one-line description.

Parameters
titleone-line description, written in lower case

Definition at line 164 of file command-definition.hpp.