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

Function main

examples/positional_validation.cpp:13–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <string>
12
13int main(int argc, char **argv) {
14
15 CLI::App app("test for positional validation");
16
17 int num1{-1}, num2{-1};
18 app.add_option("num1", num1, "first number")->check(CLI::Number);
19 app.add_option("num2", num2, "second number")->check(CLI::Number);
20 std::string file1, file2;
21 app.add_option("file1", file1, "first file")->required();
22 app.add_option("file2", file2, "second file");
23 app.validate_positionals();
24
25 CLI11_PARSE(app, argc, argv);
26
27 if(num1 != -1)
28 std::cout << "Num1 = " << num1 << '\n';
29
30 if(num2 != -1)
31 std::cout << "Num2 = " << num2 << '\n';
32
33 std::cout << "File 1 = " << file1 << '\n';
34 if(!file2.empty()) {
35 std::cout << "File 2 = " << file2 << '\n';
36 }
37
38 return 0;
39}

Callers

nothing calls this directly

Calls 4

validate_positionalsMethod · 0.80
checkMethod · 0.45
add_optionMethod · 0.45
requiredMethod · 0.45

Tested by

no test coverage detected