aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor C. Richberger <Taywee@gmx.com>2016-05-06 17:44:50 -0600
committerTaylor C. Richberger <Taywee@gmx.com>2016-05-06 17:44:50 -0600
commitd245d8139ab469cd67d75eef92d629ad3a22937c (patch)
treebbad5b8b4d4b3d4b4d485ba463521472ca8dfc18
parentimprove README.md with some benches (diff)
downloadargs.hxx-d245d8139ab469cd67d75eef92d629ad3a22937c.tar.xz
improve benchmark
-rw-r--r--README.md560
1 files changed, 302 insertions, 258 deletions
diff --git a/README.md b/README.md
index 72d233e..9dd897a 100644
--- a/README.md
+++ b/README.md
@@ -30,15 +30,15 @@ There are also somewhat extensive examples below.
It:
* lets you handle flags, flag+arguments, and positional arguments simply and
- elegently, with the full help of static typechecking.
+ elegently, with the full help of static typechecking.
* allows you to use your own types in a pretty simple way.
* lets you use count flags, and lists of all argument-accepting types.
* Allows full validation of groups of required arguments, though output isn't
- pretty when something fails group validation. User validation functions are
- accepted. Groups are fully nestable.
+ pretty when something fails group validation. User validation functions are
+ accepted. Groups are fully nestable.
* Generates pretty help for you, with some good tweakable parameters.
* Lets you customize all prefixes and most separators, allowing you to create
- an infinite number of different argument syntaxes
+ an infinite number of different argument syntaxes
* Lets you parse, by default, any type that has a stream extractor operator for
it. If this doesn't work for your uses, you can supply a function and parse
the string yourself if you like.
@@ -50,28 +50,28 @@ There are tons of things this library does not do!
## It does not yet:
* Let you decide not to allow separate-argument argument flags or joined ones
- (like disallowing `--foo bar`, requiring `--foo=bar`, or the inverse, or the
- same for short options).
+ (like disallowing `--foo bar`, requiring `--foo=bar`, or the inverse, or the
+ same for short options).
## It will not ever:
* Allow you to create subparsers like argparse in a master parser (you can do
- this yourself with iterators and multiple parsers)
+ this yourself with iterators and multiple parsers)
* Allow one argument flag to take a specific number of arguments
- (like `--foo first second`). You can instead split that with a flag list
- (`--foo first --foo second`) or a custom type extraction
- (`--foo first,second`)
+ (like `--foo first second`). You can instead split that with a flag list
+ (`--foo first --foo second`) or a custom type extraction
+ (`--foo first,second`)
* Allow you to intermix multiple different prefix types (eg. `++foo` and
- `--foo` in the same parser), though shortopt and longopt prefixes can be
- different.
+ `--foo` in the same parser), though shortopt and longopt prefixes can be
+ different.
* Allow you to have argument flags only optionally accept arguments
* Allow you to use a positional argument list before any other positional
- arguments (the last argument list will slurp all subsequent positional
- arguments). The logic for allowing this would be a lot more code than I'd
- like, and would make static checking much more difficult, requiring us to
- sort std::string arguments and pair them to positional arguments before
- assigning them, rather than what we currently do, which is assiging them as
- we go for better simplicity and speed.
+ arguments (the last argument list will slurp all subsequent positional
+ arguments). The logic for allowing this would be a lot more code than I'd
+ like, and would make static checking much more difficult, requiring us to
+ sort std::string arguments and pair them to positional arguments before
+ assigning them, rather than what we currently do, which is assiging them as
+ we go for better simplicity and speed.
# How do I use it?
@@ -100,88 +100,132 @@ This requires Doxygen
This should not really be a question you ask when you are looking for an
argument-parsing library, but I did run a simple benchmark against args, TCLAP,
-and boost::program_options, which parses the command line `-i7 -c a 2.7 --char
+and boost::program_options, which parses the command line `-i 7 -c a 2.7 --char
b 8.4 -c c 8.8 --char d` with a parser that parses -i as an int, -c as a list
of chars, and the positional parameters as a list of doubles (the command line
was originally much more complex, but TCLAP's limitations made me trim it down
so I could use a common command line across all libraries. I also have to copy
in the arguments list with every run, because TCLAP permutes its argument list
-as it runs, but that surprisingly didn't affect much.
+as it runs (and comparison would have been unfair without comparing all about
+equally), but that surprisingly didn't affect much. Also tested is pulling the
+arguments out, but that was fast compared to parsing, as would be expected.
### The run:
```
-args seconds to run: 0.793519
-tclap seconds to run: 1.35626
-boost::program_options seconds to run: 2.12119
+% g++ -obench bench.cxx -O2 -std=c++11 -lboost_program_options
+% ./bench
+args seconds to run: 0.895472
+tclap seconds to run: 1.45001
+boost::program_options seconds to run: 1.98972
+%
```
### The benchmark:
```cpp
+#undef NDEBUG
#include <iostream>
#include <chrono>
-
+#include <cassert>
#include "args.hxx"
#include <tclap/CmdLine.h>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
using namespace std::chrono;
-
+inline bool doubleequals(const double a, const double b)
+{
+ static const double delta = 0.0001;
+ const double diff = a - b;
+ return diff < delta && diff > -delta;
+}
int main()
{
- const std::vector<std::string> carguments({"-i7", "-c", "a", "2.7", "--char", "b", "8.4", "-c", "c", "8.8", "--char", "d"});
- // args
- {
- high_resolution_clock::time_point start = high_resolution_clock::now();
- for (unsigned int i = 0; i < 100000; ++i)
- {
- std::vector<std::string> arguments(carguments);
- args::ArgumentParser parser("This is a test program.", "This goes after the options.");
- args::ArgFlag<int> integer(parser, "integer", "The integer flag", args::Matcher({'i'}, {"int"}));
- args::ArgFlagList<char> characters(parser, "characters", "The character flag", args::Matcher({'c'}, {"char"}));
- args::PosArgList<double> numbers(parser, "numbers", "The numbers position list");
- parser.ParseArgs(arguments);
- }
- high_resolution_clock::duration runtime = high_resolution_clock::now() - start;
- std::cout << "args seconds to run: " << duration_cast<duration<double>>(runtime).count() << std::endl;
- }
- // tclap
- {
- high_resolution_clock::time_point start = high_resolution_clock::now();
- for (unsigned int i = 0; i < 100000; ++i)
- {
- std::vector<std::string> arguments(carguments);
- TCLAP::CmdLine cmd("Command description message", ' ', "0.9");
- TCLAP::ValueArg<int> integer("i", "int", "The integer flag", false, 0, "integer", cmd);
- TCLAP::MultiArg<char> characters("c", "char", "The character flag", false, "characters", cmd);
- TCLAP::UnlabeledMultiArg<double> numbers("numbers", "The numbers position list", false, "foo", cmd, false);
- cmd.parse(arguments);
- }
- high_resolution_clock::duration runtime = high_resolution_clock::now() - start;
- std::cout << "tclap seconds to run: " << duration_cast<duration<double>>(runtime).count() << std::endl;
- }
- // boost::program_options
- {
- high_resolution_clock::time_point start = high_resolution_clock::now();
- for (unsigned int i = 0; i < 100000; ++i)
- {
- std::vector<std::string> arguments(carguments);
- po::options_description desc("This is a test program.");
- desc.add_options()
- ("int,i", po::value<int>(), "The integer flag")
- ("char,c", po::value<std::vector<char>>(), "The character flag")
- ("numbers", po::value<std::vector<double>>(), "The numbers flag");
- po::positional_options_description p;
- p.add("numbers", -1);
- po::variables_map vm;
- po::store(po::command_line_parser(carguments).options(desc).positional(p).run(), vm);
- po::notify(vm);
- }
- high_resolution_clock::duration runtime = high_resolution_clock::now() - start;
- std::cout << "boost::program_options seconds to run: " << duration_cast<duration<double>>(runtime).count() << std::endl;
- }
- return 0;
+ const std::vector<std::string> carguments({"-i", "7", "-c", "a", "2.7", "--char", "b", "8.4", "-c", "c", "8.8", "--char", "d"});
+ const std::vector<std::string> pcarguments({"progname", "-i", "7", "-c", "a", "2.7", "--char", "b", "8.4", "-c", "c", "8.8", "--char", "d"});
+ // args
+ {
+ high_resolution_clock::time_point start = high_resolution_clock::now();
+ for (unsigned int x = 0; x < 100000; ++x)
+ {
+ std::vector<std::string> arguments(carguments);
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::ArgFlag<int> integer(parser, "integer", "The integer flag", args::Matcher({'i'}, {"int"}));
+ args::ArgFlagList<char> characters(parser, "characters", "The character flag", args::Matcher({'c'}, {"char"}));
+ args::PosArgList<double> numbers(parser, "numbers", "The numbers position list");
+ parser.ParseArgs(arguments);
+ const int i = integer.value;
+ const std::vector<char> c(characters.values);
+ const std::vector<double> n(numbers.values);
+ assert(i == 7);
+ assert(c[0] == 'a');
+ assert(c[1] == 'b');
+ assert(c[2] == 'c');
+ assert(c[3] == 'd');
+ assert(doubleequals(n[0], 2.7));
+ assert(doubleequals(n[1], 8.4));
+ assert(doubleequals(n[2], 8.8));
+ }
+ high_resolution_clock::duration runtime = high_resolution_clock::now() - start;
+ std::cout << "args seconds to run: " << duration_cast<duration<double>>(runtime).count() << std::endl;
+ }
+ // tclap
+ {
+ high_resolution_clock::time_point start = high_resolution_clock::now();
+ for (unsigned int x = 0; x < 100000; ++x)
+ {
+ std::vector<std::string> arguments(pcarguments);
+ TCLAP::CmdLine cmd("Command description message", ' ', "0.9");
+ TCLAP::ValueArg<int> integer("i", "int", "The integer flag", false, 0, "integer", cmd);
+ TCLAP::MultiArg<char> characters("c", "char", "The character flag", false, "characters", cmd);
+ TCLAP::UnlabeledMultiArg<double> numbers("numbers", "The numbers position list", false, "foo", cmd, false);
+ cmd.parse(arguments);
+ const int i = integer.getValue();
+ const std::vector<char> c(characters.getValue());
+ const std::vector<double> n(numbers.getValue());
+ assert(i == 7);
+ assert(c[0] == 'a');
+ assert(c[1] == 'b');
+ assert(c[2] == 'c');
+ assert(c[3] == 'd');
+ assert(doubleequals(n[0], 2.7));
+ assert(doubleequals(n[1], 8.4));
+ assert(doubleequals(n[2], 8.8));
+ }
+ high_resolution_clock::duration runtime = high_resolution_clock::now() - start;
+ std::cout << "tclap seconds to run: " << duration_cast<duration<double>>(runtime).count() << std::endl;
+ }
+ // boost::program_options
+ {
+ high_resolution_clock::time_point start = high_resolution_clock::now();
+ for (unsigned int x = 0; x < 100000; ++x)
+ {
+ std::vector<std::string> arguments(carguments);
+ po::options_description desc("This is a test program.");
+ desc.add_options()
+ ("int,i", po::value<int>(), "The integer flag")
+ ("char,c", po::value<std::vector<char>>(), "The character flag")
+ ("numbers", po::value<std::vector<double>>(), "The numbers flag");
+ po::positional_options_description p;
+ p.add("numbers", -1);
+ po::variables_map vm;
+ po::store(po::command_line_parser(carguments).options(desc).positional(p).run(), vm);
+ const int i = vm["int"].as<int>();
+ const std::vector<char> c(vm["char"].as<std::vector<char>>());
+ const std::vector<double> n(vm["numbers"].as<std::vector<double>>());
+ assert(i == 7);
+ assert(c[0] == 'a');
+ assert(c[1] == 'b');
+ assert(c[2] == 'c');
+ assert(c[3] == 'd');
+ assert(doubleequals(n[0], 2.7));
+ assert(doubleequals(n[1], 8.4));
+ assert(doubleequals(n[2], 8.8));
+ }
+ high_resolution_clock::duration runtime = high_resolution_clock::now() - start;
+ std::cout << "boost::program_options seconds to run: " << duration_cast<duration<double>>(runtime).count() << std::endl;
+ }
+ return 0;
}
```
@@ -218,24 +262,24 @@ All the code examples here will be complete code examples, with some output.
#include <args.hxx>
int main(int argc, char **argv)
{
- args::ArgumentParser parser("This is a test program.", "This goes after the options.");
- args::HelpFlag help(parser, "help", "Display this help menu", args::Matcher({'h'}, {"help"}));
- try
- {
- parser.ParseCLI(argc, argv);
- }
- catch (args::Help)
- {
- std::cout << parser;
- return 0;
- }
- catch (args::ParseError e)
- {
- std::cerr << e.what() << std::endl;
- std::cerr << parser;
- return 1;
- }
- return 0;
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::HelpFlag help(parser, "help", "Display this help menu", args::Matcher({'h'}, {"help"}));
+ try
+ {
+ parser.ParseCLI(argc, argv);
+ }
+ catch (args::Help)
+ {
+ std::cout << parser;
+ return 0;
+ }
+ catch (args::ParseError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser;
+ return 1;
+ }
+ return 0;
}
```
@@ -261,36 +305,36 @@ int main(int argc, char **argv)
#include <args.hxx>
int main(int argc, char **argv)
{
- args::ArgumentParser parser("This is a test program.", "This goes after the options.");
- args::Group group(parser, "This group is all exclusive:", args::Group::Validators::Xor);
- args::Flag foo(group, "foo", "The foo flag", args::Matcher({'f'}, {"foo"}));
- args::Flag bar(group, "bar", "The bar flag", args::Matcher({'b'}));
- args::Flag baz(group, "baz", "The baz flag", args::Matcher({"baz"}));
- try
- {
- parser.ParseCLI(argc, argv);
- }
- catch (args::Help)
- {
- std::cout << parser;
- return 0;
- }
- catch (args::ParseError e)
- {
- std::cerr << e.what() << std::endl;
- std::cerr << parser;
- return 1;
- }
- catch (args::ValidationError e)
- {
- std::cerr << e.what() << std::endl;
- std::cerr << parser;
- return 1;
- }
- if (foo) { std::cout << "foo" << std::endl; }
- if (bar) { std::cout << "bar" << std::endl; }
- if (baz) { std::cout << "baz" << std::endl; }
- return 0;
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::Group group(parser, "This group is all exclusive:", args::Group::Validators::Xor);
+ args::Flag foo(group, "foo", "The foo flag", args::Matcher({'f'}, {"foo"}));
+ args::Flag bar(group, "bar", "The bar flag", args::Matcher({'b'}));
+ args::Flag baz(group, "baz", "The baz flag", args::Matcher({"baz"}));
+ try
+ {
+ parser.ParseCLI(argc, argv);
+ }
+ catch (args::Help)
+ {
+ std::cout << parser;
+ return 0;
+ }
+ catch (args::ParseError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser;
+ return 1;
+ }
+ catch (args::ValidationError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser;
+ return 1;
+ }
+ if (foo) { std::cout << "foo" << std::endl; }
+ if (bar) { std::cout << "bar" << std::endl; }
+ if (baz) { std::cout << "baz" << std::endl; }
+ return 0;
}
```
@@ -339,38 +383,38 @@ Group validation failed somewhere!
#include <args.hxx>
int main(int argc, char **argv)
{
- args::ArgumentParser parser("This is a test program.", "This goes after the options.");
- args::HelpFlag help(parser, "help", "Display this help menu", args::Matcher({'h'}, {"help"}));
- args::ArgFlag<int> integer(parser, "integer", "The integer flag", args::Matcher({'i'}));
- args::ArgFlagList<char> characters(parser, "characters", "The character flag", args::Matcher({'c'}));
- args::PosArg<std::string> foo(parser, "foo", "The foo position");
- args::PosArgList<double> numbers(parser, "numbers", "The numbers position list");
- try
- {
- parser.ParseCLI(argc, argv);
- }
- catch (args::Help)
- {
- std::cout << parser;
- return 0;
- }
- catch (args::ParseError e)
- {
- std::cerr << e.what() << std::endl;
- std::cerr << parser;
- return 1;
- }
- catch (args::ValidationError e)
- {
- std::cerr << e.what() << std::endl;
- std::cerr << parser;
- return 1;
- }
- if (integer) { std::cout << "i: " << integer.value << std::endl; }
- if (characters) { for (const auto ch: characters.values) { std::cout << "c: " << ch << std::endl; } }
- if (foo) { std::cout << "f: " << foo.value << std::endl; }
- if (numbers) { for (const auto nm: numbers.values) { std::cout << "n: " << nm << std::endl; } }
- return 0;
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::HelpFlag help(parser, "help", "Display this help menu", args::Matcher({'h'}, {"help"}));
+ args::ArgFlag<int> integer(parser, "integer", "The integer flag", args::Matcher({'i'}));
+ args::ArgFlagList<char> characters(parser, "characters", "The character flag", args::Matcher({'c'}));
+ args::PosArg<std::string> foo(parser, "foo", "The foo position");
+ args::PosArgList<double> numbers(parser, "numbers", "The numbers position list");
+ try
+ {
+ parser.ParseCLI(argc, argv);
+ }
+ catch (args::Help)
+ {
+ std::cout << parser;
+ return 0;
+ }
+ catch (args::ParseError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser;
+ return 1;
+ }
+ catch (args::ValidationError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser;
+ return 1;
+ }
+ if (integer) { std::cout << "i: " << integer.value << std::endl; }
+ if (characters) { for (const auto ch: characters.values) { std::cout << "c: " << ch << std::endl; } }
+ if (foo) { std::cout << "f: " << foo.value << std::endl; }
+ if (numbers) { for (const auto nm: numbers.values) { std::cout << "n: " << nm << std::endl; } }
+ return 0;
}
```
@@ -519,51 +563,51 @@ there are unextracted characters left in the stream.
#include <args.hxx>
int main(int argc, char **argv)
{
- args::ArgumentParser parser("This is a test program with a really long description that is probably going to have to be wrapped across multiple different lines. This is a test to see how the line wrapping works", "This goes after the options. This epilog is also long enough that it will have to be properly wrapped to display correctly on the screen");
- args::HelpFlag help(parser, "HELP", "Show this help menu.", args::Matcher({'h'}, {"help"}));
- args::ArgFlag<std::string> foo(parser, "FOO", "The foo flag.", args::Matcher({'a', 'b', 'c'}, {"a", "b", "c", "the-foo-flag"}));
- args::ArgFlag<std::string> bar(parser, "BAR", "The bar flag. This one has a lot of options, and will need wrapping in the description, along with its long flag list.", args::Matcher({'d', 'e', 'f'}, {"d", "e", "f"}));
- args::ArgFlag<std::string> baz(parser, "FOO", "The baz flag. This one has a lot of options, and will need wrapping in the description, even with its short flag list.", args::Matcher({"baz"}));
- args::PosArg<std::string> pos1(parser, "POS1", "The pos1 argument.");
- args::PosArgList<std::string> poslist1(parser, "POSLIST1", "The poslist1 argument.");
- args::PosArg<std::string> pos2(parser, "POS2", "The pos2 argument.");
- args::PosArgList<std::string> poslist2(parser, "POSLIST2", "The poslist2 argument.");
- args::PosArg<std::string> pos3(parser, "POS3", "The pos3 argument.");
- args::PosArgList<std::string> poslist3(parser, "POSLIST3", "The poslist3 argument.");
- args::PosArg<std::string> pos4(parser, "POS4", "The pos4 argument.");
- args::PosArgList<std::string> poslist4(parser, "POSLIST4", "The poslist4 argument.");
- args::PosArg<std::string> pos5(parser, "POS5", "The pos5 argument.");
- args::PosArgList<std::string> poslist5(parser, "POSLIST5", "The poslist5 argument.");
- args::PosArg<std::string> pos6(parser, "POS6", "The pos6 argument.");
- args::PosArgList<std::string> poslist6(parser, "POSLIST6", "The poslist6 argument.");
- args::PosArg<std::string> pos7(parser, "POS7", "The pos7 argument.");
- args::PosArgList<std::string> poslist7(parser, "POSLIST7", "The poslist7 argument.");
- args::PosArg<std::string> pos8(parser, "POS8", "The pos8 argument.");
- args::PosArgList<std::string> poslist8(parser, "POSLIST8", "The poslist8 argument.");
- args::PosArg<std::string> pos9(parser, "POS9", "The pos9 argument.");
- args::PosArgList<std::string> poslist9(parser, "POSLIST9", "The poslist9 argument.");
- try
- {
- parser.ParseCLI(argc, argv);
- }
- catch (args::Help)
- {
- std::cout << parser;
- return 0;
- }
- catch (args::ParseError e)
- {
- std::cerr << e.what() << std::endl;
- std::cerr << parser;
- return 1;
- }
- catch (args::ValidationError e)
- {
- std::cerr << e.what() << std::endl;
- std::cerr << parser;
- return 1;
- }
- return 0;
+ args::ArgumentParser parser("This is a test program with a really long description that is probably going to have to be wrapped across multiple different lines. This is a test to see how the line wrapping works", "This goes after the options. This epilog is also long enough that it will have to be properly wrapped to display correctly on the screen");
+ args::HelpFlag help(parser, "HELP", "Show this help menu.", args::Matcher({'h'}, {"help"}));
+ args::ArgFlag<std::string> foo(parser, "FOO", "The foo flag.", args::Matcher({'a', 'b', 'c'}, {"a", "b", "c", "the-foo-flag"}));
+ args::ArgFlag<std::string> bar(parser, "BAR", "The bar flag. This one has a lot of options, and will need wrapping in the description, along with its long flag list.", args::Matcher({'d', 'e', 'f'}, {"d", "e", "f"}));
+ args::ArgFlag<std::string> baz(parser, "FOO", "The baz flag. This one has a lot of options, and will need wrapping in the description, even with its short flag list.", args::Matcher({"baz"}));
+ args::PosArg<std::string> pos1(parser, "POS1", "The pos1 argument.");
+ args::PosArgList<std::string> poslist1(parser, "POSLIST1", "The poslist1 argument.");
+ args::PosArg<std::string> pos2(parser, "POS2", "The pos2 argument.");
+ args::PosArgList<std::string> poslist2(parser, "POSLIST2", "The poslist2 argument.");
+ args::PosArg<std::string> pos3(parser, "POS3", "The pos3 argument.");
+ args::PosArgList<std::string> poslist3(parser, "POSLIST3", "The poslist3 argument.");
+ args::PosArg<std::string> pos4(parser, "POS4", "The pos4 argument.");
+ args::PosArgList<std::string> poslist4(parser, "POSLIST4", "The poslist4 argument.");
+ args::PosArg<std::string> pos5(parser, "POS5", "The pos5 argument.");
+ args::PosArgList<std::string> poslist5(parser, "POSLIST5", "The poslist5 argument.");
+ args::PosArg<std::string> pos6(parser, "POS6", "The pos6 argument.");
+ args::PosArgList<std::string> poslist6(parser, "POSLIST6", "The poslist6 argument.");
+ args::PosArg<std::string> pos7(parser, "POS7", "The pos7 argument.");
+ args::PosArgList<std::string> poslist7(parser, "POSLIST7", "The poslist7 argument.");
+ args::PosArg<std::string> pos8(parser, "POS8", "The pos8 argument.");
+ args::PosArgList<std::string> poslist8(parser, "POSLIST8", "The poslist8 argument.");
+ args::PosArg<std::string> pos9(parser, "POS9", "The pos9 argument.");
+ args::PosArgList<std::string> poslist9(parser, "POSLIST9", "The poslist9 argument.");
+ try
+ {
+ parser.ParseCLI(argc, argv);
+ }
+ catch (args::Help)
+ {
+ std::cout << parser;
+ return 0;
+ }
+ catch (args::ParseError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser;
+ return 1;
+ }
+ catch (args::ValidationError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser;
+ return 1;
+ }
+ return 0;
}
```
@@ -625,40 +669,40 @@ int main(int argc, char **argv)
#include <args.hxx>
int main(int argc, char **argv)
{
- 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);
- }
- catch (args::Help)
- {
- std::cout << parser;
- return 0;
- }
- catch (args::ParseError e)
- {
- std::cerr << e.what() << std::endl;
- std::cerr << parser;
- return 1;
- }
- catch (args::ValidationError e)
- {
- std::cerr << e.what() << std::endl;
- std::cerr << parser;
- 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;
+ 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);
+ }
+ catch (args::Help)
+ {
+ std::cout << parser;
+ return 0;
+ }
+ catch (args::ParseError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser;
+ return 1;
+ }
+ catch (args::ValidationError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser;
+ 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;
}
```
@@ -719,34 +763,34 @@ if = /tmp/test.txt
#include <args.hxx>
int main(int argc, char **argv)
{
- args::ArgumentParser parser("This is a test program.", "This goes after the options.");
- args::Group xorgroup(parser, "this group provides xor validation:", args::Group::Validators::Xor);
- args::Flag a(xorgroup, "a", "test flag", args::Matcher({'a'}));
- args::Flag b(xorgroup, "b", "test flag", args::Matcher({'b'}));
- args::Flag c(xorgroup, "c", "test flag", args::Matcher({'c'}));
- args::Group nxor(xorgroup, "this group provides all-or-none (nxor) validation:", args::Group::Validators::AllOrNone);
- args::Flag d(nxor, "d", "test flag", args::Matcher({'d'}));
- args::Flag e(nxor, "e", "test flag", args::Matcher({'e'}));
- args::Flag f(nxor, "f", "test flag", args::Matcher({'f'}));
- args::Group nxor2(nxor, "this group provides all-or-none (nxor2) validation:", args::Group::Validators::AllOrNone);
- args::Flag i(nxor2, "i", "test flag", args::Matcher({'i'}));
- args::Flag j(nxor2, "j", "test flag", args::Matcher({'j'}));
- args::Flag k(nxor2, "k", "test flag", args::Matcher({'k'}));
- args::Group nxor3(nxor, "this group provides all-or-none (nxor3) validation:", args::Group::Validators::AllOrNone);
- args::Flag l(nxor3, "l", "test flag", args::Matcher({'l'}));
- args::Flag m(nxor3, "m", "test flag", args::Matcher({'m'}));
- args::Flag n(nxor3, "n", "test flag", args::Matcher({'n'}));
- args::Group atleastone(xorgroup, "this group provides at-least-one validation:", args::Group::Validators::AtLeastOne);
- args::Flag g(atleastone, "g", "test flag", args::Matcher({'g'}));
- args::Flag o(atleastone, "o", "test flag", args::Matcher({'o'}));
- args::HelpFlag help(parser, "help", "Show this help menu", args::Matcher({'h'}, {"help"}));
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::Group xorgroup(parser, "this group provides xor validation:", args::Group::Validators::Xor);
+ args::Flag a(xorgroup, "a", "test flag", args::Matcher({'a'}));
+ args::Flag b(xorgroup, "b", "test flag", args::Matcher({'b'}));
+ args::Flag c(xorgroup, "c", "test flag", args::Matcher({'c'}));
+ args::Group nxor(xorgroup, "this group provides all-or-none (nxor) validation:", args::Group::Validators::AllOrNone);
+ args::Flag d(nxor, "d", "test flag", args::Matcher({'d'}));
+ args::Flag e(nxor, "e", "test flag", args::Matcher({'e'}));
+ args::Flag f(nxor, "f", "test flag", args::Matcher({'f'}));
+ args::Group nxor2(nxor, "this group provides all-or-none (nxor2) validation:", args::Group::Validators::AllOrNone);
+ args::Flag i(nxor2, "i", "test flag", args::Matcher({'i'}));
+ args::Flag j(nxor2, "j", "test flag", args::Matcher({'j'}));
+ args::Flag k(nxor2, "k", "test flag", args::Matcher({'k'}));
+ args::Group nxor3(nxor, "this group provides all-or-none (nxor3) validation:", args::Group::Validators::AllOrNone);
+ args::Flag l(nxor3, "l", "test flag", args::Matcher({'l'}));
+ args::Flag m(nxor3, "m", "test flag", args::Matcher({'m'}));
+ args::Flag n(nxor3, "n", "test flag", args::Matcher({'n'}));
+ args::Group atleastone(xorgroup, "this group provides at-least-one validation:", args::Group::Validators::AtLeastOne);
+ args::Flag g(atleastone, "g", "test flag", args::Matcher({'g'}));
+ args::Flag o(atleastone, "o", "test flag", args::Matcher({'o'}));
+ args::HelpFlag help(parser, "help", "Show this help menu", args::Matcher({'h'}, {"help"}));
try
{
parser.ParseCLI(argc, argv);
}
catch (args::Help)
{
- std::cout << parser;
+ std::cout << parser;
return 0;
}
catch (args::ParseError e)