summaryrefslogtreecommitdiff
path: root/src/tests/optparser.cpp
blob: ee2ea584f73f28e57487c90bbe4ebdaeab1629e8 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bu/optparser.h>
#include <bu/sio.h>
using namespace Bu;

class Opts : public Bu::OptParser
{
public:
	Opts() :
		iBob( 542 )
	{
		Option o;
		o.sUsed = slot( this, &Opts::cb );
		o.cOpt = 'x';
		o.sOpt = "things";
		o.bShortHasParams = true;
		o.sHelp = "This is the first test parameter.  It calls a function, and takes parameters.";
		addOption( o );
		
		Option o2;
		o2.sUsed = slot( this, &Opts::cb );
		o2.cOpt = 'y';
		o2.sOpt = "stuff";
		o2.bShortHasParams = false;
		o2.sHelp = "This is the second test parameter.  It does not take parameters.  However, I do want to make this part much longer to see how it looks when you add way too much text to one of these things.  It can't really be that bad, right?";
		addOption( o2 );
	
		addHelpOption('h', "help", "This help.");
	}

	int cb( StrArray aParams )
	{
		sio << "Hey, cb was called, here's a class var: " << iBob << sio.nl;
		sio << "argv[] = " << aParams << sio.nl;
		return 1;
	}

	int iBob;
};

int main( int argc, char *argv[] )
{
	Opts o;

	o.parse( argc, argv );
}