diff options
author | Jyri Sarha <jsarha@ti.com> | 2015-10-20 16:55:13 +0300 |
---|---|---|
committer | Jyri Sarha <jsarha@ti.com> | 2015-10-20 22:41:21 +0300 |
commit | f8f92d455c4a915a894111e00dd6f5ec1888bee5 (patch) | |
tree | ac85b9e440e93030e19525fd63cdf7100bc444fb /tests/optiontester.cpp | |
parent | 905eacc3b638e70f25958b7c25f09077b143e387 (diff) |
Add simple command line option parser and a tester for it
Diffstat (limited to 'tests/optiontester.cpp')
-rw-r--r-- | tests/optiontester.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/optiontester.cpp b/tests/optiontester.cpp new file mode 100644 index 0000000..ccb9579 --- /dev/null +++ b/tests/optiontester.cpp @@ -0,0 +1,29 @@ +#include <cstdio> +#include <algorithm> +#include <iostream> + +#include "cmdoptions.h" + +using namespace std; + +static map<string, CmdOption> options = { + { "test", NO_PARAM("test") }, + { "test2", HAS_PARAM("test2") }, +}; + +int main(int argc, char **argv) +{ + CmdOptions opts(argc, argv, options); + + if (opts.error().length()) { + cerr << opts.error() << opts.usage(); + return -1; + } + + for (auto p : options) + printf("Option %s set %d param %s\n", + p.first.c_str(), opts.is_set(p.first), + opts.opt_param(p.first).c_str());; + + return 0; +} |