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