koutil
Loading...
Searching...
No Matches
koutil::args::command_builder_t< Result > Class Template Reference

Builder for creating command-line command. More...

#include <command_builder.h>

Public Types

using result_t = Result
 
using command_t = command_t<result_t>
 
using option_t = option_t<result_t>
 
using argument_t = argument_t<result_t>
 

Public Member Functions

 command_builder_t (std::string_view name, std::string_view description)
 Constructs a builder for a command with name and description.
 
template<void_handle< std::optional< std::string_view >, result_t & > Handle>
 command_builder_t (std::string_view name, std::string_view description, Handle &&handle)
 Constructs a builder for a command with name, description, and handler.
 
command_builder_t && add_option (const option_t &option) &&
 Adds an option to the command.
 
command_builder_t && add_argument (const argument_t &argument) &&
 Adds a positional argument to the command.
 
command_builder_t && add_command (command_t &&command) &&
 Adds a subcommand to the command.
 
command_t build () &&
 Builds and returns the final command.
 

Private Attributes

command_t m_cmd
 

Detailed Description

template<extends_result Result = result_base_t>
class koutil::args::command_builder_t< Result >

Builder for creating command-line command.

Allows adding options, arguments, and subcommands before building the final command_t object.

Example:

auto cmd = command_builder_t("build", "Builds the project")
.add_option(option_builder_t('o', "output").description("Output file").has_value().build())
.add_argument(argument_t("source", "Source file"))
.add_command(command_builder_t("clean", "Cleans the project").build())
.build();
argument_t< result_t > argument_t
Definition command_builder.h:36
command_builder_t(std::string_view name, std::string_view description)
Constructs a builder for a command with name and description.
Definition command_builder.h:43
command_t build() &&
Builds and returns the final command.
Definition command_builder.h:91
Builder for creating command-line options.
Definition option_builder.h:29

Member Typedef Documentation

◆ argument_t

template<extends_result Result = result_base_t>
using koutil::args::command_builder_t< Result >::argument_t = argument_t<result_t>

◆ command_t

template<extends_result Result = result_base_t>
using koutil::args::command_builder_t< Result >::command_t = command_t<result_t>

◆ option_t

template<extends_result Result = result_base_t>
using koutil::args::command_builder_t< Result >::option_t = option_t<result_t>

◆ result_t

template<extends_result Result = result_base_t>
using koutil::args::command_builder_t< Result >::result_t = Result

Constructor & Destructor Documentation

◆ command_builder_t() [1/2]

template<extends_result Result = result_base_t>
koutil::args::command_builder_t< Result >::command_builder_t ( std::string_view name,
std::string_view description )
inline

Constructs a builder for a command with name and description.

Parameters
nameCommand name.
descriptionCommand description.

◆ command_builder_t() [2/2]

template<extends_result Result = result_base_t>
template<void_handle< std::optional< std::string_view >, result_t & > Handle>
koutil::args::command_builder_t< Result >::command_builder_t ( std::string_view name,
std::string_view description,
Handle && handle )
inline

Constructs a builder for a command with name, description, and handler.

Template Parameters
HandleCallable type compatible with void(std::optional<std::string_view>, result_t&).
Parameters
nameCommand name.
descriptionCommand description.
handleFunction to execute when the command is invoked.

Member Function Documentation

◆ add_argument()

template<extends_result Result = result_base_t>
command_builder_t && koutil::args::command_builder_t< Result >::add_argument ( const argument_t & argument) &&
inline

Adds a positional argument to the command.

Parameters
argumentArgument to add.
Returns
Builder.

◆ add_command()

template<extends_result Result = result_base_t>
command_builder_t && koutil::args::command_builder_t< Result >::add_command ( command_t && command) &&
inline

Adds a subcommand to the command.

Parameters
commandSubcommand to add.
Returns
Builder.

◆ add_option()

template<extends_result Result = result_base_t>
command_builder_t && koutil::args::command_builder_t< Result >::add_option ( const option_t & option) &&
inline

Adds an option to the command.

Parameters
optionOption to add.
Returns
Builder.

◆ build()

template<extends_result Result = result_base_t>
command_t koutil::args::command_builder_t< Result >::build ( ) &&
inline

Builds and returns the final command.

Returns
Constructed command_t object.

Member Data Documentation

◆ m_cmd

template<extends_result Result = result_base_t>
command_t koutil::args::command_builder_t< Result >::m_cmd
private

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