kaycxx-cli
C++ CLI library
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
kaycxx::cli::args Class Reference

Parsed command line arguments. More...

#include <kaycxx/cli/args.hpp>

Public Member Functions

 args ()=default
 Creates an empty argument collection.
 
 args (args const &)=delete
 Prevents copying parsed arguments.
 
argsoperator= (args const &)=delete
 Prevents copy-assigning parsed arguments.
 
 args (args &&other) noexcept=default
 Moves parsed arguments.
 
argsoperator= (args &&other) noexcept=default
 Move-assigns parsed arguments.
 
void validate () const
 Validates required options and subcommands and converts all positional parameters.
 
command constselected_command () const
 Returns the deepest command selected by the parsed command line.
 
bool is_selected (command const &command) const noexcept
 Checks whether a command is the deepest selected command.
 
bool is_selected (command_handle const &command) const noexcept
 Checks whether a command handle identifies the deepest selected command.
 
bool get (flag_handle const &flag) const
 Checks whether a flag was set.
 
template<parseable_value T>
T constget (option_handle< T > const &option) const
 Returns a parsed option value.
 
template<parseable_value T>
bool has (option_handle< T > const &option) const
 Checks whether an option value is available.
 
template<parseable_value T>
std::vector< T > constget (repeatable_option_handle< T > const &option) const
 Returns all parsed values of a repeatable option.
 
template<parseable_value T>
bool has (repeatable_option_handle< T > const &option) const
 Checks whether values for a repeatable option are available.
 
template<parseable_value T>
T constget (parameter_handle< T > const &parameter) const
 Returns a parsed positional parameter value.
 
template<parseable_value T>
bool has (parameter_handle< T > const &parameter) const
 Checks whether a positional parameter value is available.
 
template<parseable_value T>
std::vector< T > constget (parameters_handle< T > const &parameters) const
 Returns parsed positional parameter list values.
 
template<parseable_value T>
bool has (parameters_handle< T > const &parameters) const
 Checks whether positional parameter list values are available.
 

Friends

class command
 

Detailed Description

Parsed command line arguments.

Instances are returned directly by command::parse(). Values are queried with the handles returned by command registration methods.

Parsed arguments have unique ownership and can be moved but not copied.

Required options, subcommands and positional parameters are validated lazily when positional values are first accessed or when validate() is called explicitly.

The command that created an instance must outlive it and all handles used to access it.

Constructor & Destructor Documentation

◆ args()

kaycxx::cli::args::args ( args &&  other)
defaultnoexcept

Moves parsed arguments.

Parameters
otherParsed arguments to move from.

Member Function Documentation

◆ get() [1/5]

bool kaycxx::cli::args::get ( flag_handle const flag) const

Checks whether a flag was set.

Parameters
flagFlag handle returned by command::flag().
Returns
True if the flag was present in the parsed arguments, false otherwise.

◆ get() [2/5]

template<parseable_value T>
T const & kaycxx::cli::args::get ( option_handle< T > const option) const
inline

Returns a parsed option value.

Template Parameters
TOption value type.
Parameters
optionOption handle returned by command::option().
Returns
Parsed option value.

◆ get() [3/5]

template<parseable_value T>
T const & kaycxx::cli::args::get ( parameter_handle< T > const parameter) const
inline

Returns a parsed positional parameter value.

Template Parameters
TParameter value type.
Parameters
parameterParameter handle returned by command::parameter().
Returns
Parsed parameter value.
Exceptions
parse_errorWhen positional parameter validation fails.

◆ get() [4/5]

template<parseable_value T>
std::vector< T > const & kaycxx::cli::args::get ( parameters_handle< T > const parameters) const
inline

Returns parsed positional parameter list values.

Template Parameters
TParameter value type.
Parameters
parametersParameter list handle returned by command::parameters().
Returns
Parsed parameter values.
Exceptions
parse_errorWhen positional parameter validation fails.

◆ get() [5/5]

template<parseable_value T>
std::vector< T > const & kaycxx::cli::args::get ( repeatable_option_handle< T > const option) const
inline

Returns all parsed values of a repeatable option.

Template Parameters
TOption value type.
Parameters
optionRepeatable option handle returned by command::repeatable_option().
Returns
Parsed option values in command-line order.

◆ has() [1/4]

template<parseable_value T>
bool kaycxx::cli::args::has ( option_handle< T > const option) const
inline

Checks whether an option value is available.

Template Parameters
TOption value type.
Parameters
optionOption handle returned by command::option().
Returns
True if the option was provided or has a default value, false otherwise.

◆ has() [2/4]

template<parseable_value T>
bool kaycxx::cli::args::has ( parameter_handle< T > const parameter) const
inline

Checks whether a positional parameter value is available.

Template Parameters
TParameter value type.
Parameters
parameterParameter handle returned by command::parameter().
Returns
True if the parameter was provided or has a default value, false otherwise.
Exceptions
parse_errorWhen positional parameter validation fails.

◆ has() [3/4]

template<parseable_value T>
bool kaycxx::cli::args::has ( parameters_handle< T > const parameters) const
inline

Checks whether positional parameter list values are available.

Template Parameters
TParameter value type.
Parameters
parametersParameter list handle returned by command::parameters().
Returns
True if the parameter list was provided or has default values, false otherwise.
Exceptions
parse_errorWhen positional parameter validation fails.

◆ has() [4/4]

template<parseable_value T>
bool kaycxx::cli::args::has ( repeatable_option_handle< T > const option) const
inline

Checks whether values for a repeatable option are available.

Template Parameters
TOption value type.
Parameters
optionRepeatable option handle returned by command::repeatable_option().
Returns
True if the option was provided or has a default value, false otherwise.

◆ is_selected() [1/2]

bool kaycxx::cli::args::is_selected ( command const command) const
noexcept

Checks whether a command is the deepest selected command.

Parameters
commandCommand to check.
Returns
True when the command is selected, false otherwise.

◆ is_selected() [2/2]

bool kaycxx::cli::args::is_selected ( command_handle const command) const
noexcept

Checks whether a command handle identifies the deepest selected command.

Parameters
commandCommand handle to check.
Returns
True when the handled command is selected, false otherwise.

◆ operator=()

args & kaycxx::cli::args::operator= ( args &&  other)
defaultnoexcept

Move-assigns parsed arguments.

Parameters
otherParsed arguments to move from.
Returns
This argument collection.

◆ selected_command()

command const & kaycxx::cli::args::selected_command ( ) const

Returns the deepest command selected by the parsed command line.

The application is returned when no subcommand was selected. This allows command actions such as help to inspect the current command before validation reports a missing subcommand.

Returns
Selected command.
Exceptions
std::logic_errorWhen called on an argument collection that was not returned by command::parse().

◆ validate()

void kaycxx::cli::args::validate ( ) const

Validates required options and subcommands and converts all positional parameters.

Calling this method repeatedly has no effect after the first successful validation.

Exceptions
parse_errorWhen a required option, subcommand or positional parameter is missing, an unexpected positional argument is present, or conversion fails.

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