import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
public class Example
{
public static void main(String[] args) throws ParseException
{
brokenExample();
workingExample();
}
private static void workingExample() throws ParseException
{
String[] args = {};
Options opts = new Options();
opts.addOption(OptionBuilder.isRequired().create('v'));
GnuParser parser = new GnuParser();
CommandLine secondCL = parser.parse(opts, args);
System.out.println("Done workingExample");
}
private static void brokenExample() throws ParseException
{
String[] firstArgs = { "-v" };
String[] secondArgs = {};
Options opts = new Options();
opts.addOption(OptionBuilder.isRequired().create('v'));
GnuParser parser = new GnuParser();
CommandLine firstCL = parser.parse(opts, firstArgs);
CommandLine secondCL = parser.parse(opts, secondArgs);
System.out.println("Done brokenExample");
}
}