F
FGB
Does anyone know how to make Jakarta Commons CLI accept a negative
integer on the command line?
The example code, run as
java Test -t 4
runs as expected.
But java Test -t -3
throws an exception.
But I want to take negative ints from the command line...
Fred Burkley
(This may not be the best place to post this, but I have not been able
to find much elsewhere).
import org.apache.commons.cli.*;
public class Test {
public static void main(String args[]) {
Option testOption = new Option("t", "test", true, "Enter an int.");
Options options = new Options();
options.addOption(testOption);
CommandLineParser parser = new PosixParser();
try {
CommandLine commandLine = parser.parse(options, args);
if (commandLine.hasOption("t")) {
String opt = commandLine.getOptionValue("t");
System.out.println("Option is " + opt);
System.exit(0);
}
}
catch (ParseException pe) {
pe.printStackTrace();
}
}
}
integer on the command line?
The example code, run as
java Test -t 4
runs as expected.
But java Test -t -3
throws an exception.
But I want to take negative ints from the command line...
Fred Burkley
(This may not be the best place to post this, but I have not been able
to find much elsewhere).
import org.apache.commons.cli.*;
public class Test {
public static void main(String args[]) {
Option testOption = new Option("t", "test", true, "Enter an int.");
Options options = new Options();
options.addOption(testOption);
CommandLineParser parser = new PosixParser();
try {
CommandLine commandLine = parser.parse(options, args);
if (commandLine.hasOption("t")) {
String opt = commandLine.getOptionValue("t");
System.out.println("Option is " + opt);
System.exit(0);
}
}
catch (ParseException pe) {
pe.printStackTrace();
}
}
}