MCPcopy Create free account
hub / github.com/CLIUtils/CLI11 / main

Function main

examples/ranges.cpp:11–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include <vector>
10
11int main(int argc, char **argv) {
12
13 CLI::App app{"App to demonstrate exclusionary option groups."};
14
15 std::vector<int> range;
16 app.add_option("--range,-R", range, "A range")->expected(-2);
17
18 auto *ogroup = app.add_option_group("min_max_step", "set the min max and step");
19 int min{0}, max{0}, step{1};
20 ogroup->add_option("--min,-m", min, "The minimum")->required();
21 ogroup->add_option("--max,-M", max, "The maximum")->required();
22 ogroup->add_option("--step,-s", step, "The step")->capture_default_str();
23
24 app.require_option(1);
25
26 CLI11_PARSE(app, argc, argv);
27
28 if(!range.empty()) {
29 if(range.size() == 2) {
30 min = range[0];
31 max = range[1];
32 }
33 if(range.size() >= 3) {
34 step = range[0];
35 min = range[1];
36 max = range[2];
37 }
38 }
39 std::cout << "range is [" << min << ':' << step << ':' << max << "]\n";
40 return 0;
41}

Callers

nothing calls this directly

Calls 5

expectedMethod · 0.80
add_option_groupMethod · 0.80
require_optionMethod · 0.80
add_optionMethod · 0.45
requiredMethod · 0.45

Tested by

no test coverage detected