Switch readOnly = new SwitchBuilder().withName("R").create();
Group options = new GroupBuilder().withOption(readOnly).create();
Parser parser = new Parser();
parser.setGroup(options);
CommandLine cl = parser.parse(args); System.out.println("Arguments: " + Arrays.asList(args));
System.out.println("Readonly: " + cl.getSwitch(readOnly));If you run this with no arguments then the last line will print 'null'. If you run this with +R the last line will print 'true' If you run this with -R the last line will print 'false'
Like most options, you are not restricted to a single name and if you don't like the default +/- prefixes then you can customise the SwitchBuilder. Since Switch implements Parent you can also add arguments and child options as needed:
Argument pathToSsl = new ArgumentBuilder()
.withName("path")
.create();
Switch withSsl = new SwitchBuilder("--with-","--without-")
.withName("ssl")
.withName("openssl")
.withArgument(pathToSsl)
.create();
Triggers are used internally to identify the strings that indicate the presence of an option. In the first example above the triggers would be [+R,-R] while the second example would produce [--with-ssl,--without-ssl,--with-openssl,--without-openssl].
Hope that helps,
Rob
Java Samurai wrote:
Hi, I am wodering if you have any examples of using Switches. Also what is a trigger?
Thanks
__________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
