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

Function main

examples/arg_capture.cpp:18–34  ·  view source on GitHub ↗

This example demonstrates the use of `prefix_command` on a subcommand to capture all subsequent arguments along with an alias to make it appear as a regular options. All the values after the "sub" or "--sub" are available in the remaining() method. */

Source from the content-addressed store, hash-verified

16All the values after the "sub" or "--sub" are available in the remaining() method.
17*/
18int main(int argc, const char *argv[]) {
19
20 int value{0};
21 CLI::App app{"Test App"};
22 app.add_option("-v", value, "value");
23
24 auto *subcom = app.add_subcommand("sub", "")->prefix_command();
25 subcom->alias("--sub");
26 CLI11_PARSE(app, argc, argv);
27
28 std::cout << "value=" << value << '\n';
29 std::cout << "after Args:";
30 for(const auto &aarg : subcom->remaining()) {
31 std::cout << aarg << " ";
32 }
33 std::cout << '\n';
34}

Callers

nothing calls this directly

Calls 5

prefix_commandMethod · 0.80
aliasMethod · 0.80
remainingMethod · 0.80
add_optionMethod · 0.45
add_subcommandMethod · 0.45

Tested by

no test coverage detected