7#ifndef ARGS__COMMAND_HPP__INCLUDED
8#define ARGS__COMMAND_HPP__INCLUDED
37 bool isSubCommandRequired =
false)
41 , m_isSubCommandRequired(isSubCommandRequired)
42 , m_subCommand(nullptr)
44 if (details::isArgument(
name()) || details::isFlag(
name())) {
46 "start with \"-\" whereas you are trying to set name to \""))
57 m_valueSpecifier =
SL(
"arg");
61 m_valueSpecifier =
SL(
"args");
101 return m_valueSpecifier;
106 m_valueSpecifier = vs;
113 return m_description;
118 m_description = desc;
125 if (!m_longDescription.empty()) {
126 return m_longDescription;
128 return m_description;
134 m_longDescription = desc;
141 if (!m_values.empty()) {
142 return m_values.front();
143 }
else if (!m_defaultValues.empty()) {
144 return m_defaultValues.front();
153 if (!m_values.empty()) {
156 return m_defaultValues;
163 if (!m_defaultValues.empty()) {
164 return m_defaultValues.front();
174 m_defaultValues.push_back(v);
181 return m_defaultValues;
200 if (details::isMisspelledName(nm,
name())) {
201 possibleNames.push_back(
name());
220 if (details::isMisspelledName(nm,
name())) {
221 possibleNames.push_back(
name());
246 String(
SL(
"Addition of commands to command with "
247 "value is disallowed.")));
301 if (!arg && m_subCommand) {
302 return m_subCommand->findChild(
name);
323 String(
SL(
"Command \"")) +
name() +
SL(
"\" requires value that wasn't presented."),
330 String(
SL(
"Command \"")) +
name() +
SL(
"\" requires value that wasn't presented."),
351 if (details::isCorrectName(
name())) {
352 auto it = std::find(names.begin(), names.end(),
name());
354 if (it != names.end()) {
360 names.push_back(
name());
379 if (
isDefined() && m_isSubCommandRequired && !m_subCommand) {
404 bool m_isSubCommandRequired;
CmdLine * cmdLine() const
Base exception of the library.
Command in the command line interface.
ArgIface * findArgument(const String &n) override
bool isMisspelledCommand(const String &nm, StringList &possibleNames) const
Command & setRequired(bool on=true) override
Set required flag.
void process(Context &ctx) override
Process argument's staff, for example take values from context.
Command & setDescription(const String &desc)
Set description.
Command & setLongDescription(const String &desc)
Set long description.
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.
const String & longDescription() const override
const StringList & values() const
const String & description() const override
const StringList & defaultValues() const
Command & setValueSpecifier(const String &vs)
Set value specifier.
Command & setDefaultValues(const StringList &v)
Set default values.
const String & valueSpecifier() const override
Command & addArg(ArgPtr arg) override
Add argument.
const String & defaultValue() const override
Command & setDefaultValue(const String &v)
Set default value.
bool isMisspelledName(const String &nm, StringList &possibleNames) const override
void setCurrentSubCommand(Command *sub)
Set current subcommand.
Context is a list of words in the command line that user presented with interface for interacting wit...
String name() const override
GroupIface & addArg(ArgIface &arg)
Add argument.
void clear() override
Clear state of the argument.
Arguments m_children
List of children.
bool isMisspelledName(const String &name, StringList &possibleNames) const override
std::unique_ptr< ArgIface, details::Deleter< ArgIface > > ArgPtr
Smart pointer to the argument.
void checkCorrectnessBeforeParsing(StringList &flags, StringList &names) const override
Check correctness of the argument before parsing.
GroupIface(T &&name, bool required=false)
ArgIface * findArgument(const String &name) override
void checkCorrectnessAfterParsing() const override
Check correctness of the argument after parsing.
String eatOneValue(Ctx &context, const String &errorDescription, Cmd *cmdLine)
Eat one value.
std::string String
String type.
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.
std::vector< String > StringList
List of strings.
static const String c_string
#define UNUSED(Var)
Macro to supress warning about unused argument.
#define DISABLE_COPY(Class)
Macro for disabling copy.