aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
authorTaylor C. Richberger <taywee@gmx.com>2016-05-05 15:04:46 -0400
committerTaylor C. Richberger <taywee@gmx.com>2016-05-05 15:04:46 -0400
commit99a66cf4c4a931a066196e07c69e3d8bf813bc5d (patch)
tree2640dd5136cb6a674f3b0a7014edc095887c0c5f /test.cxx
parentMerge remote-tracking branch 'origin/1-create-flag-terminator-logic' (diff)
parentpush readme (diff)
downloadargs.hxx-99a66cf4c4a931a066196e07c69e3d8bf813bc5d.tar.xz
Merge branch '4-write-out-readme' into 'master'
push readme Closes #4 See merge request !2
Diffstat (limited to 'test.cxx')
-rw-r--r--test.cxx96
1 files changed, 23 insertions, 73 deletions
diff --git a/test.cxx b/test.cxx
index 9ce23d3..5945af6 100644
--- a/test.cxx
+++ b/test.cxx
@@ -3,39 +3,30 @@
*/
#include <iostream>
-#include <list>
-#include <clocale>
+#include <tuple>
#include <args.hxx>
+std::istream& operator>>(std::istream& is, std::tuple<int, int>& 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<double, double> &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<std::string> bararg(parser, "bar", "This is a bar flag", args::Matcher({'b', 'B'}, {"Bar", "bar"}));
- args::ArgFlag<double> 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<double> list(parser, "flaglist", "This is a list flag", args::Matcher({'l'}, {"list"}));
- args::PosArg<std::string> pos(parser, "Position", "This is a position arg");
- args::PosArgList<double> poslist(parser, "Position list", "This is a position list arg");
- args::PosArg<double> pos2(parser, "Position", "This is a position arg which has a long enough description to probably necessitate wrapping");
- args::PosArg<double> pos3(parser, "Position", "This is a position arg");
- args::PosArg<double> pos4(parser, "Pösitiön", "This is a position arg");
- args::PosArg<double> pos5(parser, "Position", "This is a position arg");
- args::PosArg<double> pos6(parser, "Position", "This is a position arg");
- args::PosArgList<double> poslist1(parser, "Position list", "This is a position list arg");
- args::PosArgList<double> poslist2(parser, "Position list", "This is a position list arg");
- args::PosArgList<double> poslist3(parser, "Position list", "This is a position list arg");
- args::PosArg<double> pos7(parser, "Position", "This is a position arg");
- args::PosArg<double> pos8(parser, "Position", "This is a position arg");
- args::PosArgList<double> poslist4(parser, "Position list", "This is a position list arg");
- args::PosArg<double> 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<std::tuple<int, int>> ints(parser, "INTS", "This takes a pair of integers.");
+ args::PosArg<std::tuple<double, double>, 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;
}