|
From: Fintan F. <fi...@gm...> - 2009-04-30 18:14:48
|
Hi David,
Thanks for the question. If I understand you correctly, what I would
recommend is this:
-Create a "virtual option" (i.e. an option that is not reachable in the
FORMAT:: section, but is defined in ARGS::) of type "enum".
e.g.
ChosenCommand:{}:{enum}:[choices="CMD1,CMD2,CMD3"]
-Create some fly rules to set the ChosenCommand option when any of your
commands are set. I'm not sure if you know about fly rules, but they are
rules that can are triggered when a certain option is set.
e.g.
CMD1 {$(CMD1)} -> ChosenCommand := {"CMD1"};
There's quite a bit going on in that example, so I'll break it down. The
first CMD1 indicates that it is a rule that should be fired when option CMD1
is set. The curly braces are used to delimit where you can write arbitrary
Java code. In the first case the code must be a boolean expression. In the
second case it is an expression that is of the correct type for the object
we are assigning to, which in this case is a String for ChosenCommand.
You could read the whole rule as: If CMD1 is set then check if CMD1 is true.
If it is true set ChosenCommand to the value "CMD1".
The $(CMD1) inside the braces is a placeholder that is converted into code
that gets the value for the CMD1 option. I'm assuming your commands are all
boolean options? If they are booleans and you are not allowing the user to
write CMD1=false (disallow by setting property allowarg="false" in the
option definition), then you can omit the {$(CMD1)} as this will always be
true. Thus:
CMD1 -> ChosenCommand := {"CMD1"};
-In the code where you direct the program's execution by the option values,
you can simply get the value of the option ChosenCommand. Note that if you
use the enum option type, we automatically generate an enum with the choices
you provided in the option's specification. The enum definition will appear
in the generated OptionInterface, and will be the return type for the
getChosenCommand() method.
I hope I've answered your question. If any of the above is not clear, or you
want to know more, just ask.
Cheers,
Fintan
On Thu, Apr 30, 2009 at 4:47 PM, David W <di...@ho...> wrote:
> The main question that I have is what would be the most efficient way to
> dispatch on options?
>
> The CLI that I'm working on basically consists of two levels of
> options--commands and options. The best analogy is something like Busybox,
> where there's a single binary (in this case jar file) that implements
> multiple commands, each with its own set of options (if any).
>
> So to be more concrete, in the "ARGS" section of the CLOPS file, I have
> command1 through commandN defined. I can check for the presence of a single
> command via iscommandNSet(). I'm wondering if there's a more efficient way
> of dispatching or testing for the command instead of doing a massive
> if/else-if statement, perhaps with enums or something (the enum could be
> used to create a proper subclass corresponding to a specific command). I
> would almost be tempted to define an enum with the same command names,
> create the correct method name programmatically (prepend "is" and append
> "Set" to the enum value), and then iterate through the list of enums,
> calling the automatically-generated method for checking to return back the
> correct enum.
>
> Basically, any pointers or suggestions at this point would be great.
> Normally I would ruminate on this for a bit, but I'm in a crunch situation
> and would appreciate some pointers. Thanks.
>
> ------------------------------
> Rediscover Hotmail®: Get e-mail storage that grows with you. Check it out.<http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Storage2_042009>
>
>
> ------------------------------------------------------------------------------
> Register Now & Save for Velocity, the Web Performance & Operations
> Conference from O'Reilly Media. Velocity features a full day of
> expert-led, hands-on workshops and two days of sessions from industry
> leaders in dedicated Performance & Operations tracks. Use code vel09scf
> and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
> _______________________________________________
> Clops-users mailing list
> Clo...@li...
> https://lists.sourceforge.net/lists/listinfo/clops-users
>
>
|