poafloc

poafloc - Parser Of Arguments For Lines Of Commands
git clone git://git.dimitrijedobrota.com/poafloc.git
Log | Files | Refs | README | LICENSE

poafloc_test.cpp (1395B)


      1 #include <iostream>
      2 #include <string>
      3 
      4 #include "poafloc/poafloc.hpp"
      5 
      6 using namespace poafloc;  // NOLINT
      7                           //
      8 int parse_opt(int key, const char* arg, Parser* parser)
      9 {
     10   std::ignore = parser;
     11 
     12   switch (key)
     13   {
     14     case 's':
     15       std::cout << 's' << std::endl;
     16       break;
     17     case 'l':
     18       std::cout << 'l' << std::endl;
     19       break;
     20     case 'a':
     21       std::cout << "a:" << arg << std::endl;
     22       break;
     23     case 'o':
     24       std::cout << "o:" << (arg != nullptr ? arg : "default") << std::endl;
     25       break;
     26     case ARG:
     27       std::cout << "arg:" << arg << std::endl;
     28       break;
     29     case INIT:
     30       std::cout << "init" << std::endl;
     31       break;
     32     case END:
     33       std::cout << "end" << std::endl;
     34       break;
     35     case SUCCESS:
     36       std::cout << "success" << std::endl;
     37       break;
     38     case ERROR:
     39       std::cout << "error" << std::endl;
     40       break;
     41     case NO_ARGS:
     42       std::cout << "noargs" << std::endl;
     43       break;
     44     default:
     45       break;
     46   }
     47 
     48   return 0;
     49 }
     50 
     51 // clang-format off
     52 static const option_t options[] = {
     53     {nullptr, 's', nullptr, 0, ""},
     54     { "long", 'l', nullptr, 0, ""},
     55     {  "arg", 'a',   "arg", 0, ""},
     56     {  "opt", 'o',   "arg", ARG_OPTIONAL, ""},
     57     {},
     58 };
     59 // clang-format on
     60 
     61 static const arg_t argp = {options, parse_opt, "", ""};
     62 
     63 int main(int argc, char* argv[])
     64 {
     65   return parse(&argp, argc, argv, 0, nullptr);
     66 }