7#ifndef ARGS__ARG_HPP__INCLUDED
8#define ARGS__ARG_HPP__INCLUDED
130 return m_defaultValue;
182 if (details::isArgument(
name) &&
name.substr(2) == m_name) {
184 }
else if (details::isFlag(
name) &&
name.substr(1) == m_flag) {
254 , m_name(std::forward<T>(
name))
255 , m_valueSpecifier(
SL(
"arg"))
267 , m_valueSpecifier(
SL(
"arg"))
278 , m_name(std::forward<T>(
name))
279 , m_valueSpecifier(
SL(
"arg"))
294 String(
SL(
"Argument \"")) +
name() +
SL(
"\" requires value that wasn't presented."),
306 if (!m_name.empty()) {
307 return SL(
"--") + m_name;
309 return SL(
"-") + m_flag;
316 if (!m_flag.empty()) {
317 if (details::isCorrectFlag(m_flag)) {
320 auto it = std::find(flags.begin(), flags.end(),
flag);
322 if (it != flags.end()) {
328 flags.push_back(
flag);
335 if (!m_name.empty()) {
336 if (details::isCorrectName(m_name)) {
339 auto it = std::find(names.begin(), names.end(),
name);
341 if (it != names.end()) {
347 names.push_back(
name);
354 if (m_flag.empty() && m_name.empty()) {
356 String(
SL(
"Arguments with empty flag and name "
357 "are disallowed.")));
370 return m_isWithValue;
403 if (!m_value.empty()) {
406 return m_defaultValue;
440 return m_valueSpecifier;
445 m_valueSpecifier = vs;
451 return m_description;
456 m_description = desc;
462 if (!m_longDescription.empty()) {
463 return m_longDescription;
465 return m_description;
471 m_longDescription = desc;
Argument with one value that can be present only once in the command line.
const String & flag() const override
Arg & setLongDescription(const String &desc)
Set long description.
virtual const String & value() const
ArgType type() const override
const String & valueSpecifier() const override
String name() const override
bool isDefined() const override
Arg & setValueSpecifier(const String &vs)
Set value specifier.
bool isRequired() const override
void checkCorrectnessBeforeParsing(StringList &flags, StringList &names) const override
Check correctness of the argument before parsing.
Arg & setDefined(bool on=true)
Set defined.
Arg & setWithValue(bool on=true)
Set is this argument with value.
bool isMisspelledName(const String &name, StringList &possibleNames) const override
virtual Arg & setDefaultValue(const String &v)
Set default value.
void process(Context &context) override
Process argument's staff, for example take values from context.
bool isWithValue() const override
Arg & setFlag(Char f)
Set flag.
Arg & setArgumentName(const String &name)
Set argument name.
Arg(Char flag, T &&name, bool isWithValue=false, bool isRequired=false)
Construct argument with flag and name.
virtual Arg & setValue(const String &v)
Set value.
const String & argumentName() const override
Arg & setDescription(const String &desc)
Set description.
const String & longDescription() const override
void clear() override
Clear state of the argument.
void checkCorrectnessAfterParsing() const override
Check correctness of the argument after parsing.
const String & description() const override
ArgIface * findArgument(const String &name) override
const String & defaultValue() const override
Arg & setRequired(bool on=true)
Set required.
CmdLine * cmdLine() const
Base exception of the library.
Context is a list of words in the command line that user presented with interface for interacting wit...
String eatOneValue(Ctx &context, const String &errorDescription, Cmd *cmdLine)
Eat one value.
std::string String
String type.
ArgType
Type of the argument.
String::value_type Char
Char type.
std::vector< String > StringList
List of strings.
#define DISABLE_COPY(Class)
Macro for disabling copy.