ChainCLI
A modern C++20 command-line interface library
Loading...
Searching...
No Matches
cli::commands::ArgumentBase Class Referenceabstract

Base class for command-line arguments. More...

#include <argument.h>

Inheritance diagram for cli::commands::ArgumentBase:
cli::commands::FlagArgument cli::commands::OptionArgumentBase cli::commands::PositionalArgumentBase cli::commands::OptionArgument< T > cli::commands::PositionalArgument< T >

Public Member Functions

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.
 
virtual std::string getOptionsDocString (const docwriting::DocWriter &writer) const =0
 Get the options documentation string for the argument.
 
virtual std::string getArgDocString (const docwriting::DocWriter &writer) const =0
 Get the argument documentation string for the argument.
 

Protected Member Functions

 ArgumentBase (std::string_view name, std::string_view optionsComment, ArgumentKind argType, bool repeatable, bool required)
 

Protected Attributes

const std::string name
 
std::string optionsComment
 
const ArgumentKind argType
 
bool repeatable {false}
 
bool required {true}
 

Detailed Description

Base class for command-line arguments.

Member Function Documentation

◆ getArgDocString()

virtual std::string cli::commands::ArgumentBase::getArgDocString ( const docwriting::DocWriter writer) const
pure virtual

Get the argument documentation string for the argument.

This string is used in the Usage section of the help message for a command and displays a textual representation of the arguments attributes (e.g. if it is required or repeatable, ...).

Parameters
writerThe documentation writer to use.
Returns
The argument documentation string for the argument.

Implemented in cli::commands::FlagArgument, cli::commands::OptionArgumentBase, and cli::commands::PositionalArgumentBase.

◆ getArgType()

constexpr ArgumentKind cli::commands::ArgumentBase::getArgType ( ) const
inlineconstexpr

Get the type of the argument.

Returns
The type of the argument.

◆ getName()

constexpr std::string_view cli::commands::ArgumentBase::getName ( ) const
inlineconstexprnoexcept

Get the name of the argument.

The name is a unique identifier for the argument within its command.

Returns
The name of the argument.

◆ getOptionComment()

constexpr std::string_view cli::commands::ArgumentBase::getOptionComment ( ) const
inlineconstexprnoexcept

Get the option comment for the argument.

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

Returns
The option comment for the argument.

◆ getOptionsDocString()

virtual std::string cli::commands::ArgumentBase::getOptionsDocString ( const docwriting::DocWriter writer) const
pure virtual

Get the options documentation string for the argument.

This string is used in the Options section of the help message for a command, where each argument is listed with its description.

Parameters
writerThe documentation writer to use.
Returns
The options documentation string for the argument.

Implemented in cli::commands::FlagArgument, cli::commands::OptionArgumentBase, and cli::commands::PositionalArgumentBase.

◆ isRepeatable()

constexpr bool cli::commands::ArgumentBase::isRepeatable ( ) const
inlineconstexprnoexcept

Check if the argument is repeatable.

Returns
True if the argument is repeatable, false otherwise.

◆ isRequired()

constexpr bool cli::commands::ArgumentBase::isRequired ( ) const
inlineconstexprnoexcept

Check if the argument is required.

Returns
True if the argument is required, false otherwise.

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