From 038815ae3a019ac56fa1c62e18c5861166d3a975 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 18 Dec 2009 15:32:37 +0000 Subject: Wow, cool, Bu::Formatter can read all the basic types now, (int, float, bool, char, etc.) and OptParser totally works. I have one last change to make to it, which is using the return value of signal type options to determine weather or not the option took a parameter at all, especially in the case of short options. --- src/tests/optparser.cpp | 63 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 21 deletions(-) (limited to 'src/tests/optparser.cpp') 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: 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 ); - - addOption( 's', "str", sVar, "Set a variable, see what it does.", "bob!"); + addHelpBanner("optparser - Test some option things..."); + + addHelpBanner("\nThis section represents options that actually have " + "callbacks, or in the case of the new system, signals/slots. They " + "all take parameters, but if they return 0 then it will be as " + "though they hadn't and the next thing will be processed normally.", + true + ); + addOption( slot( this, &Opts::yesparam ), 'x', "things", + "This is the first test parameter. It calls a function, and " + "takes a parameter." + ); + addOption( slot( this, &Opts::noparam ), 'y', "stuff", + "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?" + ); + + addHelpBanner("\nThis section represents options with no callback or " + "signal, but do have a variable to update. They use the Formatter " + "system and therefore it's very, very flexible. Any data type " + "you can read with a formatter you can set via parameter.", + true + ); + addOption( sVar, 's', "str", "Set a variable, see what it does."); + addOption( iBob, "bob", "Change iBob to wahtever you want."); + addOption( dBob, 'd', "Change dBob to wahtever you want."); + + setOverride("str", "Bob!"); - addHelpOption('h', "help", "This help."); + addHelpOption(); } - int cb( StrArray aParams ) + int yesparam( StrArray aParams ) { - sio << "Hey, cb was called, here's a class var: " << iBob << sio.nl; - sio << "argv[] = " << aParams << sio.nl; + sio << " - yesparam" << aParams << sio.nl; return 1; } + int noparam( StrArray aParams ) + { + sio << " - noparam" << aParams << sio.nl; + return 0; + } + int iBob; + float dBob; Bu::FString sVar; }; @@ -47,5 +66,7 @@ int main( int argc, char *argv[] ) o.parse( argc, argv ); sio << "sVar = \"" << o.sVar << "\"" << sio.nl; + sio << "iBob = " << o.iBob << sio.nl; + sio << "dBob = " << o.dBob << sio.nl; } -- cgit v1.2.3