You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Java Samurai <ja...@yahoo.com> on 2004/09/08 16:36:05 UTC
CLI 2.0 Switches and triggers
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [CLI] 2.0 Switches and triggers
Posted by Rob Oxspring <ro...@imapmail.org>.
A switch is simply an option that can have an on/off state associated with it.
The windows attrib command has switches to indicate whether to change the
various file attributes such as +R|-R for read only:
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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org