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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
20110505 rsz Created.
*/
#include <stdio.h>
#include "ezOptionParser.hpp"

using namespace ez;

int main(int argc, const char * argv[]) {
	ezOptionParser opt;

	opt.overview = "Demo of multiple instances of flag.";
	opt.syntax = "multi [OPTIONS]";
	opt.example = "multi -p 0,0,0 -p 2,3,4 -pt 1,1,1 --pnt 1,2,3 --point -1,1e6,-.314\n";

	opt.add(
		"0,0,0", // Default.
		1, // Required?
		3, // Number of args expected.
		',', // Delimiter if expecting multiple args.
		"Point coordinates (3-tuple). For example: -p 1,2,3.", // Help description.
		"-p",     // Flag token.
		"-pt",    // Flag token.
		"--pnt",  // Flag token.
		"--point" // Flag token.
	);

	opt.parse(argc, argv);

	std::string usage;

	std::vector<std::string> badOptions;
	if(!opt.gotRequired(badOptions)) {
		for(int i=0; i < badOptions.size(); ++i)
			std::cerr << "ERROR: Missing required option " << badOptions[i] << ".\n\n";
			
		opt.getUsage(usage);
		std::cout << usage;
		return 1;
	}

	if(!opt.gotExpected(badOptions)) {
		for(int i=0; i < badOptions.size(); ++i)
			std::cerr << "ERROR: Got unexpected number of arguments for option " << badOptions[i] << ".\n\n";
			
		opt.getUsage(usage);
		std::cout << usage;
		return 1;
	}

	std::vector< std::vector<double> > pts;
	opt.get("-p")->getMultiDoubles(pts);
	for(int j=0; j < pts.size(); ++j)
		std::cout << "Point " << j << ": " << pts[j][0] << " " << pts[j][1] << " " << pts[j][2] << std::endl;

	return 0;
}