cli20 0.1.2
A C++20 typed-schema command-line parser
Loading...
Searching...
No Matches
cli::constraint Namespace Reference

Post-parse constraint helpers. More...

Functions

template<detail::NamedProviderArg... Args>
auto one_of (const Args &... args) -> ConstraintResult
 Exactly one of the listed options must be provided.
template<detail::NamedProviderArg... Args>
auto at_most_one_of (const Args &... args) -> ConstraintResult
 At most one of the listed options may be provided.
template<detail::NamedProviderArg... Args>
auto all_of (const Args &... args) -> ConstraintResult
 All of the listed options must be provided.
template<detail::NamedProviderArg... Args>
auto all_or_none (const Args &... args) -> ConstraintResult
 Either all of the listed options must be provided, or none.
template<detail::NamedProviderArg Cond, detail::NamedProviderArg Req>
auto requires_if (const Cond &condition, const Req &required) -> ConstraintResult
 If condition is provided, required must also be provided.

Detailed Description

Post-parse constraint helpers.

Each function checks a relationship between options and returns a ConstraintResult. Combine results with && or ||:

auto constraints() -> cli::ConstraintResult {
return cli::constraint::one_of(foo, bar)
&& cli::constraint::requires_if(output, format);
}
auto one_of(const Args &... args) -> ConstraintResult
Exactly one of the listed options must be provided.
Definition constraint.hh:93
auto requires_if(const Cond &condition, const Req &required) -> ConstraintResult
If condition is provided, required must also be provided.
The result type returned by a constraints() post-parse hook.
Definition constraint.hh:29

Function Documentation

◆ all_of()

template<detail::NamedProviderArg... Args>
auto cli::constraint::all_of ( const Args &... args) -> ConstraintResult

All of the listed options must be provided.

Returns missing_required listing all names if any are absent.

Definition at line 137 of file constraint.hh.

◆ all_or_none()

template<detail::NamedProviderArg... Args>
auto cli::constraint::all_or_none ( const Args &... args) -> ConstraintResult

Either all of the listed options must be provided, or none.

Returns dependency_missing when some but not all are present.

Definition at line 154 of file constraint.hh.

◆ at_most_one_of()

template<detail::NamedProviderArg... Args>
auto cli::constraint::at_most_one_of ( const Args &... args) -> ConstraintResult

At most one of the listed options may be provided.

Returns mutually_exclusive if two or more are present simultaneously.

Definition at line 120 of file constraint.hh.

◆ one_of()

template<detail::NamedProviderArg... Args>
auto cli::constraint::one_of ( const Args &... args) -> ConstraintResult

Exactly one of the listed options must be provided.

Returns validation_failed / mutually_exclusive with a message listing all option names when the count is 0 or ≥ 2.

Definition at line 93 of file constraint.hh.

◆ requires_if()

template<detail::NamedProviderArg Cond, detail::NamedProviderArg Req>
auto cli::constraint::requires_if ( const Cond & condition,
const Req & required ) -> ConstraintResult

If condition is provided, required must also be provided.

Returns dependency_missing naming the missing option when the condition holds but the dependency is absent.

Definition at line 173 of file constraint.hh.