[te-code-users] Default values for options
Brought to you by:
atownley
|
From: Kevin R. <or...@gm...> - 2005-06-01 10:12:08
|
Hi,
I'm trying to migrate the Perl parts of our application(MillScript)
into Java, using your command line argument parser. I've run into a
problem and would appreciate any help you can offer. We have several
interfaces to MillScript, with various options and my problem lies
with options that take an optional argument, e.g.
website -s
or
website -s /a/path/to/some/folder
In this example, when no argument is specified the application
defaults to using the current folder.
For simplicity I've cut down my example Java implementation to the followin=
g:
import com.townleyenterprises.command.CommandOption;
import com.townleyenterprises.command.CommandParser;
import com.townleyenterprises.command.DefaultCommandListener;
public class OptionalArg {
public static void main( String[] args ) {
CommandOption _option =3D new CommandOption(
"status", 's', true, null, "show status", "."
);
CommandParser _parser =3D new CommandParser( "OptionalArg" );
_parser.setExitOnMissingArg( true, -100 );
_parser.addCommandListener(
new DefaultCommandListener(
"options",
new CommandOption[] {
_option
}
)
);
_parser.parse( args );
}
}
Unfortunately this doesn't work, as the default value for the argument
is only used in the auto help feature. I was wondering if this should
work as I expect it, i.e. the default value is used if no argument is
specified? As it stands, the following happens:
bash-2.05$ java -cp .:te-common.jar OptionalArg -s
error: option --status requires parameter '<arg>'. Exiting.
Usage: OptionalArg [-s|--status <arg>] [-?|--help] [--usage]
Regards,
Kevin
|