cli20 0.1.2
A C++20 typed-schema command-line parser
Loading...
Searching...
No Matches
action.hh File Reference
#include <algorithm>
#include <array>
#include <cctype>
#include <charconv>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <functional>
#include <map>
#include <optional>
#include <ranges>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <system_error>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>
#include "cli/error.hh"
#include "cli/string_literal.hh"

Go to the source code of this file.

Classes

struct  cli::ActionResult< T >
 The result type produced and consumed at each step of an action pipeline. More...
struct  cli::ActionResult< void >
 Specialisation of ActionResult for terminal (pack) actions that produce no value. More...
struct  cli::ActionCtx< T >
 Context passed to each action function during pipeline execution. More...
struct  cli::ActionCtx< void >
 Partial specialisation of ActionCtx used for intermediate pipeline steps. More...
struct  cli::Action< Fns >
 A compile-time pipeline of action functions applied sequentially to a parsed token. More...
struct  cli::Action<>
struct  cli::conversion::Integer< T >
 Converts a string token to an integral type T using std::from_chars. More...
struct  cli::conversion::Floating< T >
 Converts a string token to a floating-point type T using std::from_chars. More...
struct  cli::conversion::String
 Converts a string_view token to a std::string by copying. More...
struct  cli::conversion::Bool
 Converts a string token to bool. More...
struct  cli::conversion::Path
 Converts a string token to std::filesystem::path without filesystem validation. More...
struct  cli::conversion::ExistingFile
 Converts a string token to std::filesystem::path, requiring the path to exist and be a regular file. More...
struct  cli::conversion::ExistingDirectory
 Converts a string token to std::filesystem::path, requiring the path to exist and be a directory. More...
struct  cli::conversion::Choice< T, Mapper >
 Converts a string token to type T via a user-supplied mapper function. More...
struct  cli::conversion::NegatableResult
 Result of the negatable<> conversion. More...
struct  cli::conversion::Negatable< Prefix >
 Converts a string token to NegatableResult by detecting a compile-time negation prefix. More...
struct  cli::conversion::DefaultMissingValue< Value >
 Injects a compile-time default value when an option is invoked as a flag (no value provided). More...
struct  cli::validation::Min< MinValue >
 Validates that the input value is greater than or equal to MinValue. More...
struct  cli::validation::Max< MaxValue >
 Validates that the input value is less than or equal to MaxValue. More...
struct  cli::validation::Range< MinValue, MaxValue >
 Validates that the input value is within the closed interval [MinValue, MaxValue]. More...
struct  cli::validation::Positive
 Validates that the input value is strictly positive (> 0). More...
struct  cli::validation::NonNegative
 Validates that the input value is non-negative (>= 0). More...
struct  cli::validation::NonEmpty
 Validates that the input value is not empty (requires .empty() member). More...
struct  cli::validation::NotBlank
 Validates that the input string is not blank (not all whitespace). More...
struct  cli::validation::OneOf< Allowed >
 Validates that the input value equals one of the compile-time constants Allowed. More...
struct  cli::validation::Matches< Pattern >
 Validates that the input string matches a compile-time regular expression. More...
struct  cli::validation::Exists
 Validates that a std::filesystem::path exists on the filesystem. More...
struct  cli::validation::IsRegularFile
 Validates that a std::filesystem::path refers to a regular file. More...
struct  cli::validation::IsDirectory
 Validates that a std::filesystem::path refers to a directory. More...
struct  cli::validation::ParentExists
 Validates that the parent directory of a std::filesystem::path exists. More...
struct  cli::validation::Predicate< Pred >
 Validates a value using a user-supplied compile-time predicate. More...
struct  cli::pack::SetTrue
 Sets the bool storage to true. More...
struct  cli::pack::SetFalse
 Sets the bool storage to false. More...
struct  cli::pack::Toggle
 Flips the bool storage each time the option is seen. More...
struct  cli::pack::Increment
 Increments a std::size_t counter each time the option is seen. More...
struct  cli::pack::RejectDuplicate
 Passes the value through unchanged, but returns ErrorCode::duplicate_argument if the option has been seen more than once. More...
struct  cli::pack::SetOnce
 Stores the input value and rejects subsequent occurrences. More...
struct  cli::pack::PushUnique
 Appends the value to a std::vector<T>, rejecting duplicate values. More...
struct  cli::pack::Push
 Appends the value to a std::vector<T>. More...
struct  cli::pack::Insert
 Inserts the value into a std::set<T> (duplicates are silently ignored by the set). More...
struct  cli::pack::InsertOrAssign
struct  cli::pack::InsertOrAssign::StorageTypeImpl< Prev, bool >
struct  cli::pack::InsertOrAssign::StorageTypeImpl< Prev, true >
struct  cli::pack::Extend
struct  cli::pack::MarkPresent
 Sets a bool flag to true when the option is seen, regardless of value. More...
struct  cli::pack::StoreInto< T >
 Writes the value directly into an external variable via a T* pointer. More...
struct  cli::pack::Callback< Fn >
 Invokes a compile-time callable Fn with the parsed value as a terminal action. More...
struct  cli::action::Custom< Fn >
 Wraps a user-defined callable as a non-terminal action pipeline step. More...
struct  cli::action::PrintHelp
 Wraps the current value in a HelpRequested<T> sentinel type. More...
struct  cli::action::ExitSuccess
 Terminates the pipeline by returning a ParseError with code exit_success (or help_requested when preceded by PrintHelp). More...
struct  std::tuple_size< cli::conversion::NegatableResult >
struct  std::tuple_element< 0, cli::conversion::NegatableResult >
struct  std::tuple_element< 1, cli::conversion::NegatableResult >

Namespaces

namespace  cli
namespace  cli::conversion
 Actions that convert a raw std::string_view token to a typed value.
namespace  cli::validation
 Actions that validate a typed value after conversion.
namespace  cli::pack
 Terminal actions that write the converted (and validated) value into argument storage.
namespace  cli::action
 Actions that control the parser's control flow (help, exit).

Concepts

concept  cli::pack::CallbackInvocable

Typedefs

template<class Step, class Input>
using cli::deduce_after_type
 Deduces after_type for a non-terminal step from its operator().
template<class T, auto Mapper>
using cli::conversion::Enumeration = Choice<T, Mapper>

Functions

template<class T>
constexpr auto cli::ok (T &&value) -> ActionResult< std::remove_cvref_t< T > >
 Helper functions for constructing ActionResult objects with type deduction.
constexpr auto cli::ok () -> ActionResult< void >
 Helper function for constructing a successful ActionResult<void>.
template<class T>
constexpr auto cli::fail (ParseError error) -> ActionResult< T >
 Helper function for constructing a failure ActionResult with type deduction.
template<class T>
constexpr auto cli::ignore () -> ActionResult< T >
 Helper function for constructing an ignore ActionResult with type deduction.
template<auto Fn, auto... Fns>
constexpr auto cli::operator| (Action< Fns... >, Action< Fn >)
template<std::size_t I>
auto cli::conversion::get (NegatableResult &r) -> decltype(auto)
template<std::size_t I>
auto cli::conversion::get (const NegatableResult &r) -> decltype(auto)

Variables

template<class Step, class Input>
constexpr bool cli::deduce_accepts_input
 Deduces accepts_input for a non-terminal step from its operator().
template<std::integral T>
constexpr auto cli::conversion::integer = Action<Integer<T>{}>{}
template<std::floating_point T>
constexpr auto cli::conversion::floating = Action<Floating<T>{}>{}
template<class T, auto Mapper>
constexpr auto cli::conversion::choice = Action<Choice<T, Mapper>{}>{}
template<class T, auto Mapper>
constexpr auto cli::conversion::enumeration = Action<Enumeration<T, Mapper>{}>{}
template<StringLiteral Prefix>
constexpr auto cli::conversion::negatable = Action<Negatable<Prefix>{}>{}
constexpr auto cli::conversion::string = Action<String{}>{}
constexpr auto cli::conversion::boolean = Action<Bool{}>{}
constexpr auto cli::conversion::path = Action<Path{}>{}
constexpr auto cli::conversion::existing_file = Action<ExistingFile{}>{}
constexpr auto cli::conversion::existing_directory = Action<ExistingDirectory{}>{}
template<StringLiteral Value>
constexpr auto cli::conversion::default_missing_value
template<auto MinValue>
constexpr auto cli::validation::min = Action<Min<MinValue>{}>{}
template<auto MaxValue>
constexpr auto cli::validation::max = Action<Max<MaxValue>{}>{}
template<auto MinValue, auto MaxValue>
constexpr auto cli::validation::range = Action<Range<MinValue, MaxValue>{}>{}
template<auto... Allowed>
constexpr auto cli::validation::one_of = Action<OneOf<Allowed...>{}>{}
template<StringLiteral Pattern>
constexpr auto cli::validation::matches = Action<Matches<Pattern>{}>{}
template<auto Pred>
constexpr auto cli::validation::predicate = Action<Predicate<Pred>{}>{}
constexpr auto cli::validation::positive = Action<Positive{}>{}
constexpr auto cli::validation::non_negative = Action<NonNegative{}>{}
constexpr auto cli::validation::non_empty = Action<NonEmpty{}>{}
constexpr auto cli::validation::not_blank = Action<NotBlank{}>{}
constexpr auto cli::validation::exists = Action<Exists{}>{}
constexpr auto cli::validation::is_regular_file = Action<IsRegularFile{}>{}
constexpr auto cli::validation::is_directory = Action<IsDirectory{}>{}
constexpr auto cli::validation::parent_exists = Action<ParentExists{}>{}
constexpr auto cli::pack::set_true = Action<SetTrue{}>{}
constexpr auto cli::pack::set_false = Action<SetFalse{}>{}
constexpr auto cli::pack::toggle = Action<Toggle{}>{}
constexpr auto cli::pack::increment = Action<Increment{}>{}
constexpr auto cli::pack::set_once = Action<SetOnce{}>{}
constexpr auto cli::pack::reject_duplicate = Action<RejectDuplicate{}>{}
constexpr auto cli::pack::push_unique = Action<PushUnique{}>{}
constexpr auto cli::pack::push = Action<Push{}>{}
constexpr auto cli::pack::insert = Action<Insert{}>{}
constexpr auto cli::pack::insert_or_assign = Action<InsertOrAssign{}>{}
constexpr auto cli::pack::mark_present = Action<MarkPresent{}>{}
template<auto Fn>
constexpr auto cli::pack::callback = Action<Callback<Fn>{}>{}
template<class T>
constexpr auto cli::pack::write_to = Action<StoreInto<T>{}>{}
constexpr auto cli::action::print_help = Action<PrintHelp{}>{}
constexpr auto cli::action::exit_success = Action<ExitSuccess{}>{}
template<auto Fn>
constexpr auto cli::action::custom = Action<Custom<Fn>{}>{}