Commit 36ac4c1cc7f9faee785d7a167893757b1cad4fc9

Authored by Henry Fredrick Schreiner
1 parent e2fae48e

Adding example program for prefix program

examples/CMakeLists.txt
... ... @@ -18,3 +18,4 @@ add_cli_exe(simple simple.cpp)
18 18 add_cli_exe(subcommands subcommands.cpp)
19 19 add_cli_exe(groups groups.cpp)
20 20 add_cli_exe(inter_argument_order inter_argument_order.cpp)
  21 +add_cli_exe(prefix_command prefix_command.cpp)
... ...
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 +}
... ...