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

Builder for CliContext objects, allowing to incrementally add arguments before constructing the final context object. More...

#include <context_builder.h>

Public Member Functions

 ContextBuilder ()
 Constructs a new ContextBuilder instance.
 
ContextBuilderaddPositionalArgument (const std::string &argName, std::any &val)
 Add a positional argument to the context being built.
 
ContextBuilderaddPositionalArgument (std::string_view argName, std::any &val)
 Add a positional argument to the context being built.
 
ContextBuilderaddRepeatablePositionalArgument (const std::string &argName, const std::vector< std::any > &vals)
 Add a repeatable positional argument to the context being built.
 
ContextBuilderaddRepeatablePositionalArgument (std::string_view argName, const std::vector< std::any > &vals)
 Add a repeatable positional argument to the context being built.
 
ContextBuilderaddOptionArgument (const std::string &argName, std::any &val)
 Add an optional argument to the context being built.
 
ContextBuilderaddOptionArgument (std::string_view argName, std::any &val)
 Add an optional argument to the context being built.
 
ContextBuilderaddRepeatableOptionArgument (const std::string &argName, const std::vector< std::any > &vals)
 Add a repeatable optional argument to the context being built.
 
ContextBuilderaddRepeatableOptionArgument (std::string_view argName, const std::vector< std::any > &vals)
 Add a repeatable optional argument to the context being built.
 
ContextBuilderaddFlagArgument (const std::string &argName)
 Add a flag argument to the context being built.
 
ContextBuilderaddFlagArgument (std::string_view argName)
 Add a flag argument to the context being built.
 
bool isArgPresent (const std::string &argName) const
 Checks if an argument with the given name is present in the context being built.
 
std::unique_ptr< CliContextbuild (cli::logging::AbstractLogger &logger)
 Builds the final CliContext object from the accumulated arguments.
 

Detailed Description

Builder for CliContext objects, allowing to incrementally add arguments before constructing the final context object.

Member Function Documentation

◆ addFlagArgument() [1/2]

inline_t ContextBuilder & cli::ContextBuilder::addFlagArgument ( const std::string &  argName)

Add a flag argument to the context being built.

Parameters
argNamethe name of the flag argument
Returns
a reference to this ContextBuilder instance

◆ addFlagArgument() [2/2]

inline_t ContextBuilder & cli::ContextBuilder::addFlagArgument ( std::string_view  argName)

Add a flag argument to the context being built.

Parameters
argNamethe name of the flag argument
Returns
a reference to this ContextBuilder instance

◆ addOptionArgument() [1/2]

inline_t ContextBuilder & cli::ContextBuilder::addOptionArgument ( const std::string &  argName,
std::any &  val 
)

Add an optional argument to the context being built.

Parameters
argNamethe name of the optional argument
valvalue of the optional argument
Returns
a reference to this ContextBuilder instance

◆ addOptionArgument() [2/2]

inline_t ContextBuilder & cli::ContextBuilder::addOptionArgument ( std::string_view  argName,
std::any &  val 
)

Add an optional argument to the context being built.

Parameters
argNamethe name of the optional argument
valvalue of the optional argument
Returns
a reference to this ContextBuilder instance

◆ addPositionalArgument() [1/2]

inline_t ContextBuilder & cli::ContextBuilder::addPositionalArgument ( const std::string &  argName,
std::any &  val 
)

Add a positional argument to the context being built.

Parameters
argNamethe name of the positional argument
valvalue of the positional argument
Returns
a reference to this ContextBuilder instance

◆ addPositionalArgument() [2/2]

inline_t ContextBuilder & cli::ContextBuilder::addPositionalArgument ( std::string_view  argName,
std::any &  val 
)

Add a positional argument to the context being built.

Parameters
argNamethe name of the positional argument
valvalue of the positional argument
Returns
a reference to this ContextBuilder instance

◆ addRepeatableOptionArgument() [1/2]

inline_t ContextBuilder & cli::ContextBuilder::addRepeatableOptionArgument ( const std::string &  argName,
const std::vector< std::any > &  vals 
)

Add a repeatable optional argument to the context being built.

Parameters
argNamethe name of the repeatable optional argument
valsvalues of the repeatable optional argument
Returns
a reference to this ContextBuilder instance

◆ addRepeatableOptionArgument() [2/2]

inline_t ContextBuilder & cli::ContextBuilder::addRepeatableOptionArgument ( std::string_view  argName,
const std::vector< std::any > &  vals 
)

Add a repeatable optional argument to the context being built.

Parameters
argNamethe name of the repeatable optional argument
valsvalues of the repeatable optional argument
Returns
a reference to this ContextBuilder instance

◆ addRepeatablePositionalArgument() [1/2]

inline_t ContextBuilder & cli::ContextBuilder::addRepeatablePositionalArgument ( const std::string &  argName,
const std::vector< std::any > &  vals 
)

Add a repeatable positional argument to the context being built.

Parameters
argNamethe name of the repeatable positional argument
valsvalues of the repeatable positional argument
Returns
a reference to this ContextBuilder instance

◆ addRepeatablePositionalArgument() [2/2]

inline_t ContextBuilder & cli::ContextBuilder::addRepeatablePositionalArgument ( std::string_view  argName,
const std::vector< std::any > &  vals 
)

Add a repeatable positional argument to the context being built.

Parameters
argNamethe name of the repeatable positional argument
valsvalues of the repeatable positional argument
Returns
a reference to this ContextBuilder instance

◆ build()

inline_t std::unique_ptr< CliContext > cli::ContextBuilder::build ( cli::logging::AbstractLogger logger)

Builds the final CliContext object from the accumulated arguments.

Parameters
loggerthe logger instance to use in the created context
Returns
a unique_ptr to the created CliContext object

◆ isArgPresent()

inline_t bool cli::ContextBuilder::isArgPresent ( const std::string &  argName) const

Checks if an argument with the given name is present in the context being built.

Parameters
argNamethe name of the argument to search for
Returns
true if the argument is present, false otherwise

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