13#include <unordered_map>
14#include <unordered_set>
25namespace kaycxx::cli {
125 template <parseable_value T>
127 return std::any_cast<T const&>(values_.at(&
option.definition()));
139 template <parseable_value T>
141 return values_.contains(&
option.definition());
152 template <parseable_value T>
154 return std::any_cast<std::vector<T>
const&>(values_.at(&
option.definition()));
165 template <parseable_value T>
167 return values_.contains(&
option.definition());
181 template <parseable_value T>
184 return std::any_cast<T const&>(parameters_.at(&
parameter.definition()));
198 template <parseable_value T>
201 return parameters_.contains(&
parameter.definition());
215 template <parseable_value T>
218 return std::any_cast<std::vector<T>
const&>(parameters_.at(&
parameters.definition()));
232 template <parseable_value T>
235 return parameters_.contains(&
parameters.definition());
242 command const* selected_command_ =
nullptr;
245 bool missing_subcommand_ =
false;
248 std::unordered_set<switch_base const*> flags_;
251 std::unordered_map<switch_base const*, std::any> values_;
254 std::vector<option_base const*> required_option_definitions_;
257 std::vector<parameter_base const*> parameter_definitions_;
260 std::vector<std::string> positional_values_;
263 mutable std::unordered_map<parameter_base const*, std::any> parameters_;
266 mutable bool validated_ =
false;
Parsed command line arguments.
Definition args.hpp:41
bool has(parameter_handle< T > const ¶meter) const
Checks whether a positional parameter value is available.
Definition args.hpp:199
std::vector< T > const & get(repeatable_option_handle< T > const &option) const
Returns all parsed values of a repeatable option.
Definition args.hpp:153
args & operator=(args &&other) noexcept=default
Move-assigns parsed arguments.
T const & get(parameter_handle< T > const ¶meter) const
Returns a parsed positional parameter value.
Definition args.hpp:182
bool is_selected(command const &command) const noexcept
Checks whether a command is the deepest selected command.
command const & selected_command() const
Returns the deepest command selected by the parsed command line.
bool has(repeatable_option_handle< T > const &option) const
Checks whether values for a repeatable option are available.
Definition args.hpp:166
args & operator=(args const &)=delete
Prevents copy-assigning parsed arguments.
args(args &&other) noexcept=default
Moves parsed arguments.
bool get(flag_handle const &flag) const
Checks whether a flag was set.
args(args const &)=delete
Prevents copying parsed arguments.
bool is_selected(command_handle const &command) const noexcept
Checks whether a command handle identifies the deepest selected command.
std::vector< T > const & get(parameters_handle< T > const ¶meters) const
Returns parsed positional parameter list values.
Definition args.hpp:216
void validate() const
Validates required options and subcommands and converts all positional parameters.
args()=default
Creates an empty argument collection.
T const & get(option_handle< T > const &option) const
Returns a parsed option value.
Definition args.hpp:126
bool has(parameters_handle< T > const ¶meters) const
Checks whether positional parameter list values are available.
Definition args.hpp:233
bool has(option_handle< T > const &option) const
Checks whether an option value is available.
Definition args.hpp:140
Handle for a registered command.
Definition command_handle.hpp:25
Common base class for an application and its commands.
Definition command.hpp:45
Handle for a registered flag.
Definition flag_handle.hpp:22
Command line flag definition.
Definition flag.hpp:22
Handle for a registered option.
Definition option_handle.hpp:25
Typed command line option definition.
Definition option.hpp:156
Handle for a registered positional parameter.
Definition parameter_handle.hpp:25
Typed single positional parameter definition.
Definition parameter.hpp:33
Handle for a registered positional parameter list.
Definition parameters_handle.hpp:28
Typed positional parameter list definition.
Definition parameters.hpp:38
Handle for a registered repeatable option.
Definition repeatable_option_handle.hpp:25
Defines the flag handle type.
Defines the option handle type.
Defines the common base class for positional parameters.
Defines the positional parameter handle type.
Defines the positional parameter list handle type.
Defines the repeatable option handle type.
Defines the common base class for flags and options.