Commit 36ac4c1cc7f9faee785d7a167893757b1cad4fc9
1 parent
e2fae48e
Adding example program for prefix program
Showing
2 changed files
with
33 additions
and
0 deletions
examples/CMakeLists.txt
examples/prefix_command.cpp
0 → 100644
| 1 | +#include "CLI/CLI.hpp" | |
| 2 | + | |
| 3 | +int main(int argc, char **argv) { | |
| 4 | + | |
| 5 | + CLI::App app("Prefix command app"); | |
| 6 | + app.prefix_command(); | |
| 7 | + | |
| 8 | + std::vector<int> vals; | |
| 9 | + app.add_option("--vals,-v", vals) | |
| 10 | + ->expected(1); | |
| 11 | + | |
| 12 | + std::vector<std::string> more_comms; | |
| 13 | + try { | |
| 14 | + more_comms = app.parse(argc, argv); | |
| 15 | + } catch(const CLI::ParseError &e) { | |
| 16 | + return app.exit(e); | |
| 17 | + } | |
| 18 | + | |
| 19 | + std::cout << "Prefix:"; | |
| 20 | + for(int v : vals) | |
| 21 | + std::cout << v << ":"; | |
| 22 | + | |
| 23 | + std::cout << std::endl << "Remaining commands: "; | |
| 24 | + | |
| 25 | + // Perfer to loop over from beginning, not "pop" order | |
| 26 | + std::reverse(std::begin(more_comms), std::end(more_comms)); | |
| 27 | + for(auto com : more_comms) | |
| 28 | + std::cout << com << " "; | |
| 29 | + std::cout << std::endl; | |
| 30 | + | |
| 31 | + return 0; | |
| 32 | +} | ... | ... |