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

Function main

examples/shapes.cpp:11–56  ·  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("load shapes");
14
15 app.set_help_all_flag("--help-all");
16 auto *circle = app.add_subcommand("circle", "draw a circle")->immediate_callback();
17 double radius{0.0};
18 int circle_counter{0};
19 circle->callback([&radius, &circle_counter] {
20 ++circle_counter;
21 std::cout << "circle" << circle_counter << " with radius " << radius << '\n';
22 });
23
24 circle->add_option("radius", radius, "the radius of the circle")->required();
25
26 auto *rect = app.add_subcommand("rectangle", "draw a rectangle")->immediate_callback();
27 double edge1{0.0};
28 double edge2{0.0};
29 int rect_counter{0};
30 rect->callback([&edge1, &edge2, &rect_counter] {
31 ++rect_counter;
32 if(edge2 == 0) {
33 edge2 = edge1;
34 }
35 std::cout << "rectangle" << rect_counter << " with edges [" << edge1 << ',' << edge2 << "]\n";
36 edge2 = 0;
37 });
38
39 rect->add_option("edge1", edge1, "the first edge length of the rectangle")->required();
40 rect->add_option("edge2", edge2, "the second edge length of the rectangle");
41
42 auto *tri = app.add_subcommand("triangle", "draw a rectangle")->immediate_callback();
43 std::vector<double> sides;
44 int tri_counter = 0;
45 tri->callback([&sides, &tri_counter] {
46 ++tri_counter;
47
48 std::cout << "triangle" << tri_counter << " with sides [" << CLI::detail::join(sides) << "]\n";
49 });
50
51 tri->add_option("sides", sides, "the side lengths of the triangle");
52
53 CLI11_PARSE(app, argc, argv);
54
55 return 0;
56}

Callers

nothing calls this directly

Calls 7

joinFunction · 0.85
set_help_all_flagMethod · 0.80
immediate_callbackMethod · 0.80
callbackMethod · 0.80
add_subcommandMethod · 0.45
requiredMethod · 0.45
add_optionMethod · 0.45

Tested by

no test coverage detected