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

Represents positional arguments in the CLI. More...

#include <positional_argument.h>

Inheritance diagram for cli::commands::PositionalArgument< T >:
cli::commands::PositionalArgumentBase cli::commands::TypedArgumentBase cli::commands::ArgumentBase

Public Member Functions

 PositionalArgument (std::string_view name, std::string_view optionsComment="", bool required=true, bool repeatable=false)
 Construct a new Positional Argument object.
 
std::any parseToValue (const std::string &input) const override
 Parse the input string to the argument's value type.
 
PositionalArgument< T > & withOptionsComment (std::string_view comment)
 Set the options comment for the argument.
 
PositionalArgument< T > & withRequired (bool req)
 Set whether the argument is required.
 
PositionalArgument< T > & withRepeatable (bool rep)
 Set whether the argument can be specified multiple times.
 
PositionalArgument< T > && create ()
 
- Public Member Functions inherited from cli::commands::PositionalArgumentBase
 PositionalArgumentBase (std::string_view name, std::string_view optionsComment, bool repeatable, bool required, std::type_index t)
 Construct a new Positional 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.
 
- 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.
 

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 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}
 

Detailed Description

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

Represents positional arguments in the CLI.

Template Parameters
TThe type of the argument's value.

Constructor & Destructor Documentation

◆ PositionalArgument()

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

Construct a new Positional Argument object.

Template Parameters
TThe type of the argument's value.
Parameters
nameThe name of the argument.
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::PositionalArgument< 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 >
PositionalArgument< T > & cli::commands::PositionalArgument< 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 >
PositionalArgument< T > & cli::commands::PositionalArgument< 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 >
PositionalArgument< T > & cli::commands::PositionalArgument< T >::withRequired ( bool  req)
inline

Set whether the argument is required.

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

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