31#ifndef ARGS__COMMAND_HPP__INCLUDED
32#define ARGS__COMMAND_HPP__INCLUDED
59 template<
typename T >
62 bool isSubCommandRequired =
false )
65 , m_isDefined( false )
66 , m_isSubCommandRequired( isSubCommandRequired )
67 , m_subCommand( nullptr )
69 if( details::isArgument(
name() ) || details::isFlag(
name() ) )
71 "start with \"-\" whereas you are trying to set name to \"" ) ) +
76 String(
SL(
"Command can't be with empty name." ) ) );
82 m_valueSpecifier =
SL(
"arg" );
88 m_valueSpecifier =
SL(
"args" );
129 return m_valueSpecifier;
134 m_valueSpecifier = vs;
140 return m_description;
145 m_description = desc;
151 if( !m_longDescription.empty() )
152 return m_longDescription;
154 return m_description;
159 m_longDescription = desc;
165 if( !m_values.empty() )
166 return m_values.front();
167 else if( !m_defaultValues.empty() )
168 return m_defaultValues.front();
176 if( !m_values.empty() )
179 return m_defaultValues;
185 if( !m_defaultValues.empty() )
186 return m_defaultValues.front();
195 m_defaultValues.push_back( v );
201 return m_defaultValues;
219 if( details::isMisspelledName( nm,
name() ) )
221 possibleNames.push_back(
name() );
239 if( details::isMisspelledName( nm,
name() ) )
241 possibleNames.push_back(
name() );
266 "value is disallowed." ) ) );
291 const String & n )
override
318 if( !arg && m_subCommand )
341 name() +
SL(
"\" requires value that wasn't presented." ),
350 SL(
"\" requires value that wasn't presented." ),
372 if( details::isCorrectName(
name() ) )
374 auto it = std::find( names.begin(), names.end(),
name() );
376 if( it != names.end() )
378 "with name \"" ) ) +
name() +
SL(
"\"." ) );
380 names.push_back(
name() );
384 name() +
SL(
"\" for the command." ) );
398 if(
isDefined() && m_isSubCommandRequired && !m_subCommand )
423 bool m_isSubCommandRequired;
CmdLine * cmdLine() const
Base exception of the library.
CmdLine is class that holds all rguments and parse command line arguments in the correspondence with ...
Command in the command line interface.
ArgIface * findArgument(const String &n) override
bool isMisspelledCommand(const String &nm, StringList &possibleNames) const
void process(Context &ctx) override
Process argument's staff, for example take values from context.
void setDefaultValues(const StringList &v)
Set default values.
void setDefaultValue(const String &v)
ArgIface * findChild(const String &name)
bool isDefined() const override
void checkCorrectnessBeforeParsing(StringList &flags, StringList &names) const override
Check correctness of the argument before parsing.
bool isWithValue() const override
ArgType type() const override
Command(T &&nm, ValueOptions opt=ValueOptions::NoValue, bool isSubCommandRequired=false)
const String & value() const
void checkCorrectnessAfterParsing() const override
Check correctness of the argument after parsing.
void clear() override
Clear state of the argument.
void setDescription(const String &desc)
Set description.
const String & longDescription() const override
void addArg(ArgPtr arg) override
Add argument.
const StringList & values() const
const String & description() const override
const StringList & defaultValues() const
void setRequired(bool on=true) override
Set required flag.
const String & defaultValue() const
const String & valueSpecifier() const override
void setValueSpecifier(const String &vs)
Set value specifier.
bool isMisspelledName(const String &nm, StringList &possibleNames) const override
void setCurrentSubCommand(Command *sub)
Set current subcommand.
void setLongDescription(const String &desc)
Set long description.
Context is a list of words in the command line that user presented with interface for interacting wit...
Interface for the groups.
String name() const override
std::unique_ptr< ArgIface, details::Deleter< ArgIface > > ArgPtr
Smart pointer to the argument.
void clear() override
Clear state of the argument.
Arguments m_children
List of children.
bool isMisspelledName(const String &name, StringList &possibleNames) const override
void addArg(ArgIface &arg)
Add argument.
void checkCorrectnessBeforeParsing(StringList &flags, StringList &names) const override
Check correctness of the argument before parsing.
ArgIface * findArgument(const String &name) override
void checkCorrectnessAfterParsing() const override
Check correctness of the argument after parsing.
HelpPrinter is a class that prints help.
std::string String
String type.
std::vector< String > StringList
List of strings.
String eatOneValue(Ctx &context, const String &errorDescription, Cmd *cmdLine)
Eat one value.
ArgType
Type of the argument.
ValueOptions
Options for value property.
bool eatValues(Ctx &context, Container &container, const String &errorDescription, Cmd *cmdLine)
Eat values in context.
#define UNUSED(Var)
Macro to supress warning about unused argument.
#define DISABLE_COPY(Class)
Macro for disabling copy.