01: package argparser;
02:
03: /**
04: * Gives a very simple example of the use of
05: * {@link argparser.ArgParser ArgParser}.
06: */
07: public class SimpleExample {
08: /**
09: * Run this to invoke command line parsing.
10: */
11: public static void main(String[] args) {
12: // create holder objects for storing results ...
13:
14: DoubleHolder theta = new DoubleHolder();
15: StringHolder fileName = new StringHolder();
16: BooleanHolder debug = new BooleanHolder();
17:
18: // create the parser and specify the allowed options ...
19:
20: ArgParser parser = new ArgParser("java argparser.SimpleExample");
21: parser.addOption("-theta %f #theta value (in degrees)", theta);
22: parser.addOption("-file %s #name of the operating file",
23: fileName);
24: parser.addOption(
25: "-debug %v #enables display of debugging info", debug);
26:
27: // and then match the arguments
28:
29: parser.matchAllArgs(args);
30:
31: // now print out the values
32:
33: System.out.println("theta=" + theta.value);
34: System.out.println("fileName=" + fileName.value);
35: System.out.println("debug=" + debug.value);
36: }
37: }
|