By janeyoung on Nov 06, 2008
GlassFish v3 Prelude formally launched today. It's one of a kind app server based on OSGi modularity and HK2 component systems. With this architecture, developers can easily provide commands making CLI extensible and pluggable. Sreeni has written an excellent blog on creating a CLI command. He also provided a sample command to try out. Believe me... it's that easy to write CLI command.
In this blog, I'll extend a bit more about defining a command's options and operands. Command's options and operands are variables denoted by the Param annotation:
Parameters can be added to @Param to determine the characteristic of the option or operand. Here are the valid parameters:
- primary - indicate that the variable is an operand. If not defined, then the variable is an option.
- name - option name. If not defined, then the variable name is the name of the option.
- optional - indicate if the variable is an optional option or operand. Default is true.
- DefaultValue - default value of the option or operand.
- AcceptableValues - comma separated acceptable values
- ShortName - short name for te option. It has to be specified wit one character. e.g. "asadmin command-name -<short-name>=<option-value>"
- Password - indicate if option is a password. If the option is a password, then the password value is declared in a passwordfile with the entrh, AS_ADMIN_<option-name>;=<password-value>. The passwordfile is passed in to asadmin command with --passwordfile option.
|Type|| Command line is specified as:|
|java.lan.String|| --option-name option-value |
|java.util.Properties|| --option-name key1=value1;key2=value2|
|java.util.List|| --option-name value1,value2|
|java.util.Boolean|| --option-name if option is true and --no-option-name if option is false.|