31#ifndef ARGS__ARG_HPP__INCLUDED
32#define ARGS__ARG_HPP__INCLUDED
61 template<
typename T >
82 template<
typename T >
155 return m_defaultValue;
173 if( details::isMisspelledName(
name,
209 if( details::isArgument(
name ) &&
name.substr( 2 ) == m_name )
211 else if( details::isFlag(
name ) &&
name.substr( 1 ) == m_flag )
271template<
typename T >
273 bool isWithValue,
bool isRequired )
274 : m_isWithValue( isWithValue )
275 , m_isRequired( isRequired )
276 , m_isDefined( false )
278 , m_name( std::forward< T > ( name ) )
279 , m_valueSpecifier(
SL(
"arg" ) )
285 bool isWithValue,
bool isRequired )
286 : m_isWithValue( isWithValue )
287 , m_isRequired( isRequired )
288 , m_isDefined( false )
290 , m_valueSpecifier(
SL(
"arg" ) )
294template<
typename T >
296 bool isWithValue,
bool isRequired )
297 : m_isWithValue( isWithValue )
298 , m_isRequired( isRequired )
299 , m_isDefined( false )
300 , m_name( std::forward< T > ( name ) )
301 , m_valueSpecifier(
SL(
"arg" ) )
321 SL(
"\" requires value that wasn't presented." ),
329 name() +
SL(
"\" already defined." ) );
335 if( !m_name.empty() )
336 return SL(
"--" ) + m_name;
338 return SL(
"-" ) + m_flag;
345 if( !m_flag.empty() )
347 if( details::isCorrectFlag( m_flag ) )
351 auto it = std::find( flags.begin(), flags.end(),
flag );
353 if( it != flags.end() )
355 "with flag \"" ) ) +
flag +
SL(
"\"." ) );
357 flags.push_back(
flag );
361 m_flag +
SL(
"\"." ) );
364 if( !m_name.empty() )
366 if( details::isCorrectName( m_name ) )
370 auto it = std::find( names.begin(), names.end(),
name );
372 if( it != names.end() )
374 "with name \"" ) ) +
name +
SL(
"\"." ) );
376 names.push_back(
name );
380 m_name +
SL(
"\"." ) );
383 if( m_flag.empty() && m_name.empty() )
385 "are disallowed." ) ) );
399 return m_isWithValue;
435 if( !m_value.empty() )
438 return m_defaultValue;
474 return m_valueSpecifier;
480 m_valueSpecifier = vs;
486 return m_description;
492 m_description = desc;
498 if( !m_longDescription.empty() )
499 return m_longDescription;
501 return m_description;
507 m_longDescription = desc;
Argument with one value that can be present only once in the command line.
const String & flag() const override
virtual const String & value() const
ArgType type() const override
const String & valueSpecifier() const override
String name() const override
bool isDefined() const override
bool isRequired() const override
virtual void setValue(const String &v)
Set value.
void setValueSpecifier(const String &vs)
Set value specifier.
virtual const String & defaultValue() const
void checkCorrectnessBeforeParsing(StringList &flags, StringList &names) const override
Check correctness of the argument before parsing.
bool isMisspelledName(const String &name, StringList &possibleNames) const override
void setRequired(bool on=true)
Set required.
void process(Context &context) override
Process argument's staff, for example take values from context.
bool isWithValue() const override
void setDefined(bool on=true)
Set defined.
void setFlag(Char f)
Set flag.
void setArgumentName(const String &name)
Set argument name.
Arg(Char flag, T &&name, bool isWithValue=false, bool isRequired=false)
Construct argument with flag and name.
const String & argumentName() const override
void setLongDescription(const String &desc)
Set long description.
const String & longDescription() const override
void clear() override
Clear state of the argument.
void setWithValue(bool on=true)
Set is this argument with value.
void setDescription(const String &desc)
Set description.
void checkCorrectnessAfterParsing() const override
Check correctness of the argument after parsing.
const String & description() const override
ArgIface * findArgument(const String &name) override
virtual void setDefaultValue(const String &v)
Set default value.
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...
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.
String::value_type Char
Char type.
#define DISABLE_COPY(Class)
Macro for disabling copy.