| 11 | #include <string> |
| 12 | |
| 13 | int main(int argc, char **argv) { |
| 14 | CLI::AutoTimer give_me_a_name("This is a timer"); |
| 15 | |
| 16 | CLI::App app("K3Pi goofit fitter"); |
| 17 | |
| 18 | CLI::App_p impOpt = std::make_shared<CLI::App>("Important"); |
| 19 | std::string file; |
| 20 | CLI::Option *opt = impOpt->add_option("-f,--file,file", file, "File name")->required(); |
| 21 | |
| 22 | int count{0}; |
| 23 | CLI::Option *copt = impOpt->add_flag("-c,--count", count, "Counter")->required(); |
| 24 | |
| 25 | CLI::App_p otherOpt = std::make_shared<CLI::App>("Other"); |
| 26 | double value{0.0}; // = 3.14; |
| 27 | otherOpt->add_option("-d,--double", value, "Some Value"); |
| 28 | |
| 29 | // add the subapps to the main one |
| 30 | app.add_subcommand(impOpt); |
| 31 | app.add_subcommand(otherOpt); |
| 32 | |
| 33 | try { |
| 34 | app.parse(argc, argv); |
| 35 | } catch(const CLI::ParseError &e) { |
| 36 | return app.exit(e); |
| 37 | } |
| 38 | |
| 39 | std::cout << "Working on file: " << file << ", direct count: " << impOpt->count("--file") |
| 40 | << ", opt count: " << opt->count() << '\n'; |
| 41 | std::cout << "Working on count: " << count << ", direct count: " << impOpt->count("--count") |
| 42 | << ", opt count: " << copt->count() << '\n'; |
| 43 | std::cout << "Some value: " << value << '\n'; |
| 44 | |
| 45 | return 0; |
| 46 | } |
nothing calls this directly
no test coverage detected