diff options
| author | Taylor C. Richberger <Taywee@gmx.com> | 2016-05-05 13:28:26 -0600 | 
|---|---|---|
| committer | Taylor C. Richberger <Taywee@gmx.com> | 2016-05-05 13:28:26 -0600 | 
| commit | 26f403ba8fee8c768155ab53cac92b77b3080162 (patch) | |
| tree | c5446b03e9eef454e18405f1d240872096219175 /test.cxx | |
| parent | Merge branch '4-write-out-readme' into 'master' (diff) | |
| download | args.hxx-1.0.3.tar.xz | |
great improvements to readme1.0.3
Diffstat (limited to 'test.cxx')
| -rw-r--r-- | test.cxx | 41 | 
1 files changed, 16 insertions, 25 deletions
@@ -3,30 +3,19 @@   */  #include <iostream> -#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)  { -    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."); +    args::ArgumentParser parser("This command likes to break your disks"); +    parser.LongPrefix("/"); +    parser.LongSeparator(":"); +    args::HelpFlag help(parser, "HELP", "Show this help menu.", args::Matcher({"help"})); +    args::ArgFlag<long> bs(parser, "BYTES", "Block size", args::Matcher({"bs"}), 512); +    args::ArgFlag<long> skip(parser, "BYTES", "Bytes to skip", args::Matcher({"skip"}), 0); +    args::ArgFlag<std::string> input(parser, "BLOCK SIZE", "Block size", args::Matcher({"if"})); +    args::ArgFlag<std::string> output(parser, "BLOCK SIZE", "Block size", args::Matcher({"of"}));      try      {          parser.ParseCLI(argc, argv); @@ -42,13 +31,15 @@ int main(int argc, char **argv)          std::cerr << parser.Help();          return 1;      } -    if (ints) +    catch (args::ValidationError e)      { -        std::cout << "ints found: " << std::get<0>(ints.value) << " and " << std::get<1>(ints.value) << std::endl; -    } -    if (doubles) -    { -        std::cout << "doubles found: " << std::get<0>(doubles.value) << " and " << std::get<1>(doubles.value) << std::endl; +        std::cerr << e.what() << std::endl; +        std::cerr << parser.Help(); +        return 1;      } +    std::cout << "bs = " << bs.value << std::endl; +    std::cout << "skip = " << skip.value << std::endl; +    if (input) { std::cout << "if = " << input.value << std::endl; } +    if (output) { std::cout << "of = " << output.value << std::endl; }      return 0;  }  | 
