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

Function add_option

tests/ComplexTypeTest.cpp:15–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13using cx = std::complex<double>;
14
15CLI::Option *
16add_option(CLI::App &app, std::string name, cx &variable, std::string description = "", bool defaulted = false) {
17 CLI::callback_t fun = [&variable](CLI::results_t res) {
18 double x = 0, y = 0;
19 bool worked = CLI::detail::lexical_cast(res[0], x) && CLI::detail::lexical_cast(res[1], y);
20 if(worked)
21 variable = cx(x, y);
22 return worked;
23 };
24
25 CLI::Option *opt = app.add_option(name, fun, description, defaulted);
26 opt->type_name("COMPLEX")->type_size(2);
27 if(defaulted) {
28 std::stringstream out;
29 out << variable;
30 opt->default_str(out.str());
31 }
32 return opt;
33}
34
35TEST_CASE_METHOD(TApp, "AddingComplexParser", "[complex]") {
36

Callers 7

add_optionMethod · 0.85
add_option_no_streamMethod · 0.85
add_option_functionMethod · 0.85
add_optionsMethod · 0.85
_add_flag_internalMethod · 0.85
set_configMethod · 0.85

Calls 3

type_sizeMethod · 0.80
lexical_castFunction · 0.70
add_optionMethod · 0.45

Tested by

no test coverage detected