cli11
Loading...
Searching...
No Matches
option.cpp File Reference
module cli11

The option type: one command-line option and everything set on it. More...

#include <cerrno>
import cli11:validators;
import std;

Classes

class  cli::option_base_t
 Settings shared by option_t and option_defaults_t. More...
class  cli::option_defaults_t
 The settings newly created options inherit. More...
class  cli::option_t
 One command-line option, flag, or positional argument. More...

Typedefs

using cli::results_t = std::vector<std::string>
 The raw strings collected for one option.
using cli::callback_t = std::function<bool(const results_t &)>
 The callback that turns collected results into a bound value.
using cli::option_ptr_t = std::unique_ptr<option_t>
 Owning handle to an option.
using cli::validator_ptr_t = std::shared_ptr<validator_t>
 Shared handle to a validator.

Enumerations

enum class  cli::multi_option_policy_t : std::uint8_t {
  reject , take_last , take_first , join ,
  take_all , sum , reverse
}
 What to do when an option is given more values than it expects. More...
enum class  cli::callback_priority_t : std::uint8_t {
  first_pre_help = 0 , first = 1 , pre_requirements_check_pre_help = 2 , pre_requirements_check = 3 ,
  normal_pre_help = 4 , normal = 5 , last_pre_help = 6 , last = 7
}
 When an option's callback runs relative to the others. More...

Detailed Description

The option type: one command-line option and everything set on it.

An cli::option_t is created by app_t::add_option and configured by chaining: app.add_option("--f,--file", path)->required()->check(cli::existing_file). Settings shared with app_t's option defaults live in cli::option_base_t.

An option moves through cli::option_t::option_state_t as parsing proceeds: raw results are collected, validated, reduced according to the multi-option policy, and finally handed to the callback that writes the bound variable.

Enumeration Type Documentation

◆ callback_priority_t

enum class cli::callback_priority_t : std::uint8_t
exportstrong

When an option's callback runs relative to the others.

Enumerator
first_pre_help 

Before everything, including help.

first 

Before everything else.

pre_requirements_check_pre_help 

Before requirement checks and help.

pre_requirements_check 

Before requirement checks.

normal_pre_help 

In the usual position, but before help.

normal 

The usual position.

last_pre_help 

After everything, but before help.

last 

After everything else.

◆ multi_option_policy_t

enum class cli::multi_option_policy_t : std::uint8_t
exportstrong

What to do when an option is given more values than it expects.

Enumerator
reject 

Report an error. Named reject because throw is a keyword.

take_last 

Keep only the last value.

take_first 

Keep only the first value.

join 

Join every value with the option's delimiter.

take_all 

Keep every value.

sum 

Add the values together.

reverse 

Keep every value, in reverse order.