aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorTaylor C. Richberger <Taywee@gmx.com>2016-05-05 13:30:35 -0600
committerTaylor C. Richberger <Taywee@gmx.com>2016-05-05 13:30:35 -0600
commitcb1dc1eba6e129e01b70572a6eac681e63d50c26 (patch)
tree6517a52634288d49adf96b73b8869b0effe80639 /README.md
parentgreat improvements to readme (diff)
downloadargs.hxx-cb1dc1eba6e129e01b70572a6eac681e63d50c26.tar.xz
fix readme example1.0.4
Diffstat (limited to 'README.md')
-rw-r--r--README.md37
1 files changed, 37 insertions, 0 deletions
diff --git a/README.md b/README.md
index 2ff204d..a3b0989 100644
--- a/README.md
+++ b/README.md
@@ -189,6 +189,43 @@ Group validation failed somewhere!
## Argument flags, Positional arguments, lists
```c++
+#include <iostream>
+#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.Help();
+ return 0;
+ }
+ catch (args::ParseError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser.Help();
+ return 1;
+ }
+ catch (args::ValidationError e)
+ {
+ std::cerr << e.what() << std::endl;
+ std::cerr << parser.Help();
+ 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;
+}
```
```shell