From 8aefb080e01b3b3d9da50e366cae60d1e6165ff3 Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Thu, 5 May 2016 13:03:25 -0600 Subject: push readme --- test.cxx | 96 ++++++++++++++++------------------------------------------------ 1 file changed, 23 insertions(+), 73 deletions(-) (limited to 'test.cxx') diff --git a/test.cxx b/test.cxx index 9ce23d3..5945af6 100644 --- a/test.cxx +++ b/test.cxx @@ -3,39 +3,30 @@ */ #include -#include -#include +#include #include +std::istream& operator>>(std::istream& is, std::tuple& ints) +{ + is >> std::get<0>(ints); + is.get(); + is >> std::get<1>(ints); + return is; +} + +void DoublesReader(const std::string &name, const std::string &value, std::tuple &destination) +{ + size_t commapos = 0; + std::get<0>(destination) = std::stod(value, &commapos); + std::get<1>(destination) = std::stod(std::string(value, commapos + 1)); +} + int main(int argc, char **argv) { - setlocale(LC_ALL, ""); - args::ArgumentParser parser("This is a test program. It has a lot of really cool things about it, and it also has a really really long description line that is going to necessitate some line breaks.", "As you saw above, this previously mentioned program has a lot of long things, and therefore necessitates some line breaking"); - args::Group mutexgroup(parser, "Group test", args::Group::Validators::AllOrNone); - args::Flag aflag(mutexgroup, "a", "This is flag a", args::Matcher({'a'})); - args::Flag bflag(mutexgroup, "b", "This is flag b", args::Matcher({'b'})); - args::Flag cflag(mutexgroup, "c", "This is flag c", args::Matcher({'c'})); - args::HelpFlag help(parser, "help", "Display this help menu", args::Matcher({'h'}, {"help"})); - args::Flag fooflag(parser, "foo", "This is a foo flag", args::Matcher({'f', 'F'}, {"Foo", "foo"})); - args::ArgFlag bararg(parser, "bar", "This is a bar flag", args::Matcher({'b', 'B'}, {"Bar", "bar"})); - args::ArgFlag baz(parser, "baz", "This is a baz flag, and it is long enough that it needs to be wrapped.", args::Matcher({'z', 'Z'}, {"Baz", "baz"})); - args::ArgFlagList list(parser, "flaglist", "This is a list flag", args::Matcher({'l'}, {"list"})); - args::PosArg pos(parser, "Position", "This is a position arg"); - args::PosArgList poslist(parser, "Position list", "This is a position list arg"); - args::PosArg pos2(parser, "Position", "This is a position arg which has a long enough description to probably necessitate wrapping"); - args::PosArg pos3(parser, "Position", "This is a position arg"); - args::PosArg pos4(parser, "Pösitiön", "This is a position arg"); - args::PosArg pos5(parser, "Position", "This is a position arg"); - args::PosArg pos6(parser, "Position", "This is a position arg"); - args::PosArgList poslist1(parser, "Position list", "This is a position list arg"); - args::PosArgList poslist2(parser, "Position list", "This is a position list arg"); - args::PosArgList poslist3(parser, "Position list", "This is a position list arg"); - args::PosArg pos7(parser, "Position", "This is a position arg"); - args::PosArg pos8(parser, "Position", "This is a position arg"); - args::PosArgList poslist4(parser, "Position list", "This is a position list arg"); - args::PosArg pos9(parser, "Position", "This is a position arg"); - args::Counter counter(parser, "counter", "This is a counter flag", args::Matcher({'c'})); + args::ArgumentParser parser("This is a test program."); + args::PosArg> ints(parser, "INTS", "This takes a pair of integers."); + args::PosArg, DoublesReader> doubles(parser, "DOUBLES", "This takes a pair of doubles."); try { parser.ParseCLI(argc, argv); @@ -51,54 +42,13 @@ int main(int argc, char **argv) std::cerr << parser.Help(); return 1; } - if (aflag) - { - std::cout << "A flag found" << std::endl; - } - if (bflag) - { - std::cout << "B flag found" << std::endl; - } - if (cflag) - { - std::cout << "C flag found" << std::endl; - } - if (fooflag) + if (ints) { - std::cout << "Foo flag found" << std::endl; + std::cout << "ints found: " << std::get<0>(ints.value) << " and " << std::get<1>(ints.value) << std::endl; } - if (bararg) + if (doubles) { - std::cout << "Bar arg found: " << bararg.value << std::endl; + std::cout << "doubles found: " << std::get<0>(doubles.value) << " and " << std::get<1>(doubles.value) << std::endl; } - if (baz) - { - std::cout << "Baz arg found: " << baz.value << std::endl; - } - if (counter) - { - std::cout << "counter found: " << counter.count << std::endl; - } - if (list) - { - std::cout << "list found: " << std::endl; - for (const auto &item: list.values) - { - std::cout << "- " << item << std::endl; - } - } - if (pos) - { - std::cout << "pos found: " << pos.value << std::endl; - } - if (poslist) - { - std::cout << "poslist found: " << std::endl; - for (const auto &item: poslist.values) - { - std::cout << "- " << item << std::endl; - } - } - return 0; } -- cgit v1.2.1