summaryrefslogtreecommitdiff
path: root/tests/optiontester.cpp
blob: ccb957971de4906c3e85d39da94875c3160e0c50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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;
}