log.debug("processing arguments: " + Strings.join(args, ","));
if (args.length == 0)
{
throw new CommandException("Command requires arguments");
}
String sopts = "-:c";
LongOpt[] lopts =
{
new LongOpt("count", LongOpt.NO_ARGUMENT, null, 'c"),
};
Getopt getopt = new Getopt(null, args, sopts, lopts);
getopt.setOpterr(false);
int code;
int argidx = 0;
while ((code = getopt.getopt()) != -1)
{
switch (code)
{
case ':":
throw new CommandException
("Option requires an argument: " + args[getopt.getOptind() - 1]);
case '?":
throw new CommandException
("Invalid (or ambiguous) option: " + args[getopt.getOptind() - 1]);
// non-option arguments
case 1:
{
String arg = getopt.getOptarg();
switch (argidx++)
{
case 0:
query = arg;
log.debug("query: " + query);
break;
default:
throw new CommandException("Unused argument: " + arg);
}
break;
}
// Show count
case 'c":
displayCount = true;
break;
}
}