ChainCLI
A modern C++20 command-line interface library
Loading...
Searching...
No Matches
cli::commands::OptionArgument< T > Class Template Reference

Represents option arguments in the CLI. More...

#include <option_argument.h>

Inheritance diagram for cli::commands::OptionArgument< T >:
cli::commands::OptionArgumentBase cli::commands::TypedArgumentBase cli::commands::ArgumentBase cli::commands::FlaggedArgumentBase

Public Member Functions

 OptionArgument (std::string_view name, std::string_view valueName, std::string_view shortName="", std::string_view optionsComment="", bool required=false, bool repeatable=false)
 Construct a new Option Argument object.
 
std::any parseToValue (const std::string &input) const override
 Parse the input string to the argument's value type.
 
OptionArgument< T > & withOptionsComment (std::string_view comment)
 Set the options comment for the argument.
 
OptionArgument< T > & withRequired (bool req)
 Set whether the argument is required.
 
OptionArgument< T > & withShortName (std::string_view name)
 Set the short name for the argument.
 
OptionArgument< T > & withRepeatable (bool rep)
 Set whether the argument can be specified multiple times.
 
- Public Member Functions inherited from cli::commands::OptionArgumentBase
 OptionArgumentBase (std::string_view name, std::string_view optionsComment, bool repeatable, bool required, std::type_index t, std::string_view shortName, std::string_view valueName)
 Construct a new Option Argument object.
 
std::string getOptionsDocString (const docwriting::DocWriter &writer) const override
 Get the options documentation string for the argument.
 
std::string getArgDocString (const docwriting::DocWriter &writer) const override
 Get the argument documentation string for the argument.
 
constexpr std::string_view getValueName () const noexcept
 
- Public Member Functions inherited from cli::commands::TypedArgumentBase
std::type_index getType () const
 Get the type of the argument.
 
- Public Member Functions inherited from cli::commands::ArgumentBase
constexpr std::string_view getName () const noexcept
 Get the name of the argument.
 
constexpr std::string_view getOptionComment () const noexcept
 Get the option comment for the argument.
 
constexpr bool isRequired () const noexcept
 Check if the argument is required.
 
constexpr bool isRepeatable () const noexcept
 Check if the argument is repeatable.
 
constexpr ArgumentKind getArgType () const
 Get the type of the argument.
 
- Public Member Functions inherited from cli::commands::FlaggedArgumentBase
constexpr std::string_view getShortName () const noexcept
 Get the short name of the argument.
 

Additional Inherited Members

- Protected Member Functions inherited from cli::commands::TypedArgumentBase
 TypedArgumentBase (std::type_index t)
 
- Protected Member Functions inherited from cli::commands::ArgumentBase
 ArgumentBase (std::string_view name, std::string_view optionsComment, ArgumentKind argType, bool repeatable, bool required)
 
- Protected Member Functions inherited from cli::commands::FlaggedArgumentBase
 FlaggedArgumentBase (std::string_view shortName)
 
- Protected Attributes inherited from cli::commands::OptionArgumentBase
const std::string valueName
 
- Protected Attributes inherited from cli::commands::TypedArgumentBase
const std::type_index type
 
- Protected Attributes inherited from cli::commands::ArgumentBase
const std::string name
 
std::string optionsComment
 
const ArgumentKind argType
 
bool repeatable {false}
 
bool required {true}
 
- Protected Attributes inherited from cli::commands::FlaggedArgumentBase
std::string shortName
 

Detailed Description

template<typename T>
class cli::commands::OptionArgument< T >

Represents option arguments in the CLI.

Template Parameters
TThe type of the argument's value.

Constructor & Destructor Documentation

◆ OptionArgument()

template<typename T >
cli::commands::OptionArgument< T >::OptionArgument ( std::string_view  name,
std::string_view  valueName,
std::string_view  shortName = "",
std::string_view  optionsComment = "",
bool  required = false,
bool  repeatable = false 
)
inlineexplicit

Construct a new Option Argument object.

Template Parameters
TThe type of the argument's value.
Parameters
nameThe name of the argument (usually starts with "--").
valueNameThe name of the value for the argument.
shortNameThe short name for the argument (usually starts with "-").
optionsCommentA comment describing this argument.
requiredWhether the argument is required.
repeatableWhether the argument can be specified multiple times.

Member Function Documentation

◆ parseToValue()

template<typename T >
std::any cli::commands::OptionArgument< T >::parseToValue ( const std::string &  input) const
inlineoverridevirtual

Parse the input string to the argument's value type.

Parameters
inputThe input string to parse.
Returns
The parsed value as std::any.

Implements cli::commands::TypedArgumentBase.

◆ withOptionsComment()

template<typename T >
OptionArgument< T > & cli::commands::OptionArgument< T >::withOptionsComment ( std::string_view  comment)
inline

Set the options comment for the argument.

The options comment is a brief description of the argument's purpose, used in help messages and documentation.

Parameters
commentThe options comment to set.
Returns
A reference to this argument.

◆ withRepeatable()

template<typename T >
OptionArgument< T > & cli::commands::OptionArgument< T >::withRepeatable ( bool  rep)
inline

Set whether the argument can be specified multiple times.

Parameters
repWhether the argument can be specified multiple times.
Returns
A reference to this argument.

◆ withRequired()

template<typename T >
OptionArgument< T > & cli::commands::OptionArgument< T >::withRequired ( bool  req)
inline

Set whether the argument is required.

Parameters
reqWhether the argument should be required.
Returns
A reference to this argument.

◆ withShortName()

template<typename T >
OptionArgument< T > & cli::commands::OptionArgument< T >::withShortName ( std::string_view  name)
inline

Set the short name for the argument.

The short name is a single-character alias for the argument, usually prefixed with a single dash (e.g., "-h" for "--help").

Parameters
nameThe short name to set.
Returns
A reference to this argument.

The documentation for this class was generated from the following file: