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

Represents a flag argument in the CLI. More...

#include <flag_argument.h>

Inheritance diagram for cli::commands::FlagArgument:
cli::commands::ArgumentBase cli::commands::FlaggedArgumentBase

Public Member Functions

 FlagArgument (std::string_view name, std::string_view shortName="", std::string_view optionsComment="", bool isRequired=false)
 Construct a new Flag 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.
 
FlagArgumentwithOptionsComment (std::string_view comment)
 Set the options comment for the argument.
 
FlagArgumentwithRequired (bool req)
 Set whether the argument is required.
 
FlagArgumentwithShortName (std::string_view name)
 Set the short name for 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::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::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

Represents a flag argument in the CLI.

Constructor & Destructor Documentation

◆ FlagArgument()

cli::commands::FlagArgument::FlagArgument ( std::string_view  name,
std::string_view  shortName = "",
std::string_view  optionsComment = "",
bool  isRequired = false 
)
inlineexplicit

Construct a new Flag Argument object.

Parameters
nameThe name of the argument (usually starts with "--").
shortNameThe short name of the argument (usually starts with "-").
optionsCommentA comment describing this argument.
isRequiredWhether the argument is required.

Member Function Documentation

◆ getArgDocString()

inline_t std::string cli::commands::FlagArgument::getArgDocString ( const docwriting::DocWriter writer) const
overridevirtual

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.

Implements cli::commands::ArgumentBase.

◆ getOptionsDocString()

inline_t std::string cli::commands::FlagArgument::getOptionsDocString ( const docwriting::DocWriter writer) const
overridevirtual

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.

Implements cli::commands::ArgumentBase.

◆ withOptionsComment()

FlagArgument & cli::commands::FlagArgument::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.

◆ withRequired()

FlagArgument & cli::commands::FlagArgument::withRequired ( bool  req)
inline

Set whether the argument is required.

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

◆ withShortName()

FlagArgument & cli::commands::FlagArgument::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 files: