1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 12:13:52 +00:00
CLI11/examples/ranges.cpp
Philip Top 6b7f6a7480 Value initialization (#416)
* work on the flags book chapter and making sure the values are initialized properly.

* Fix initialization of values used in flags or options

* update some formatting and more brace initialization

* update more formatting and fix a incorrect initializer

* more formatting and some error fixes

* more formatting

* Small formatting fix

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2020-01-27 09:42:03 -06:00

36 lines
987 B
C++

#include <CLI/CLI.hpp>
#include <iostream>
#include <vector>
int main(int argc, char **argv) {
CLI::App app{"App to demonstrate exclusionary option groups."};
std::vector<int> range;
app.add_option("--range,-R", range, "A range")->expected(-2);
auto ogroup = app.add_option_group("min_max_step", "set the min max and step");
int min{0}, max{0}, step{1};
ogroup->add_option("--min,-m", min, "The minimum")->required();
ogroup->add_option("--max,-M", max, "The maximum")->required();
ogroup->add_option("--step,-s", step, "The step", true);
app.require_option(1);
CLI11_PARSE(app, argc, argv);
if(!range.empty()) {
if(range.size() == 2) {
min = range[0];
max = range[1];
}
if(range.size() >= 3) {
step = range[0];
min = range[1];
max = range[2];
}
}
std::cout << "range is [" << min << ':' << step << ':' << max << "]\n";
return 0;
}