aboutsummaryrefslogtreecommitdiff
path: root/src/tests/optparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/optparser.cpp')
-rw-r--r--src/tests/optparser.cpp63
1 files changed, 42 insertions, 21 deletions
diff --git a/src/tests/optparser.cpp b/src/tests/optparser.cpp
index 5cf82bd..f5df7ed 100644
--- a/src/tests/optparser.cpp
+++ b/src/tests/optparser.cpp
@@ -8,35 +8,54 @@ public:
8 Opts() : 8 Opts() :
9 iBob( 542 ) 9 iBob( 542 )
10 { 10 {
11 Option o; 11 addHelpBanner("optparser - Test some option things...");
12 o.sUsed = slot( this, &Opts::cb ); 12
13 o.cOpt = 'x'; 13 addHelpBanner("\nThis section represents options that actually have "
14 o.sOpt = "things"; 14 "callbacks, or in the case of the new system, signals/slots. They "
15 o.bShortHasParams = true; 15 "all take parameters, but if they return 0 then it will be as "
16 o.sHelp = "This is the first test parameter. It calls a function, and takes parameters."; 16 "though they hadn't and the next thing will be processed normally.",
17 addOption( o ); 17 true
18 18 );
19 Option o2; 19 addOption( slot( this, &Opts::yesparam ), 'x', "things",
20 o2.sUsed = slot( this, &Opts::cb ); 20 "This is the first test parameter. It calls a function, and "
21 o2.cOpt = 'y'; 21 "takes a parameter."
22 o2.sOpt = "stuff"; 22 );
23 o2.bShortHasParams = false; 23 addOption( slot( this, &Opts::noparam ), 'y', "stuff",
24 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?"; 24 "This is the second test parameter. It does not take "
25 addOption( o2 ); 25 "parameters. However, I do want to make this part much longer to "
26 26 "see how it looks when you add way too much text to one of these "
27 addOption( 's', "str", sVar, "Set a variable, see what it does.", "bob!"); 27 "things. It can't really be that bad, right?"
28 );
29
30 addHelpBanner("\nThis section represents options with no callback or "
31 "signal, but do have a variable to update. They use the Formatter "
32 "system and therefore it's very, very flexible. Any data type "
33 "you can read with a formatter you can set via parameter.",
34 true
35 );
36 addOption( sVar, 's', "str", "Set a variable, see what it does.");
37 addOption( iBob, "bob", "Change iBob to wahtever you want.");
38 addOption( dBob, 'd', "Change dBob to wahtever you want.");
39
40 setOverride("str", "Bob!");
28 41
29 addHelpOption('h', "help", "This help."); 42 addHelpOption();
30 } 43 }
31 44
32 int cb( StrArray aParams ) 45 int yesparam( StrArray aParams )
33 { 46 {
34 sio << "Hey, cb was called, here's a class var: " << iBob << sio.nl; 47 sio << " - yesparam" << aParams << sio.nl;
35 sio << "argv[] = " << aParams << sio.nl;
36 return 1; 48 return 1;
37 } 49 }
38 50
51 int noparam( StrArray aParams )
52 {
53 sio << " - noparam" << aParams << sio.nl;
54 return 0;
55 }
56
39 int iBob; 57 int iBob;
58 float dBob;
40 Bu::FString sVar; 59 Bu::FString sVar;
41}; 60};
42 61
@@ -47,5 +66,7 @@ int main( int argc, char *argv[] )
47 o.parse( argc, argv ); 66 o.parse( argc, argv );
48 67
49 sio << "sVar = \"" << o.sVar << "\"" << sio.nl; 68 sio << "sVar = \"" << o.sVar << "\"" << sio.nl;
69 sio << "iBob = " << o.iBob << sio.nl;
70 sio << "dBob = " << o.dBob << sio.nl;
50} 71}
51 72