new LongOpt("quiet", LongOpt.NO_ARGUMENT, null, 'q'),
new LongOpt("user", LongOpt.REQUIRED_ARGUMENT, null, 'u'),
new LongOpt("password", LongOpt.REQUIRED_ARGUMENT, null, 'p'),
};
Getopt getopt = new Getopt(PROGRAM_NAME, args, sopts, lopts);
int code;
PROCESS_ARGUMENTS:
while ((code = getopt.getopt()) != -1)
{
switch (code)
{
case ':':
case '?':
// for now both of these should exit with error status
System.exit(1);
break; // for completeness
// non-option arguments
case 1:
{
// create the command
commandName = getopt.getOptarg();
log.debug("Command name: " + commandName);
// pass the remaining arguments (if any) to the command for processing
int i = getopt.getOptind();
if (args.length > i)
{
commandArgs = new String[args.length - i];
System.arraycopy(args, i, commandArgs, 0, args.length - i);
}
else
{
commandArgs = new String[0];
}
// Log the command options
log.debug("Command arguments: " + Strings.join(commandArgs, ","));
// We are done, execute the command
break PROCESS_ARGUMENTS;
}
// show command line help
case 'h':
displayHelp();
System.exit(0);
break; // for completeness
// Show command help
case 'H':
commandName = getopt.getOptarg();
commandHelp = true;
break PROCESS_ARGUMENTS;
// help-commands
case 0x1000:
twiddle.displayCommandList();
System.exit(0);
break; // for completeness
case 'c':
// Try value as a URL
String props = getopt.getOptarg();
try
{
cmdProps = new URL(props);
}
catch (MalformedURLException e)
{
log.debug("Failed to use cmd props as url", e);
File path = new File(props);
if( path.exists() == false )
{
String msg = "Failed to locate command props: " + props
+ " as URL or file";
throw new IllegalArgumentException(msg);
}
cmdProps = path.toURL();
}
break;
// set a system property
case 'D':
{
String arg = getopt.getOptarg();
String name, value;
int i = arg.indexOf("=");
if (i == -1)
{
name = arg;
value = "true";
}
else
{
name = arg.substring(0, i);
value = arg.substring(i + 1, arg.length());
}
System.setProperty(name, value);
break;
}
// Set the JNDI server URL
case 's':
twiddle.setServerURL(getopt.getOptarg());
break;
// Set the adapter JNDI name
case 'a':
twiddle.setAdapterName(getopt.getOptarg());
break;
case 'u':
String username = getopt.getOptarg();
SecurityAssociation.setPrincipal(new SimplePrincipal(username));
break;
case 'p':
String password = getopt.getOptarg();
SecurityAssociation.setCredential(password);
break;
// Enable quiet operations
case 'q':