Search code examples
javacommand-line-interfaceapache-commons-cli

Java Apache Commons CLI does not find setArgs()


I am trying to get multiple arguments passed to a java program. The Apache Commons CLI interface has been set up correctly and works. However, when I try to use

setArgs(Option.UNLIMITED_VALUES), it gives me an error

The method setArgs(int) is undefined for the type Options.

My code looks like this:

import java.io.Console;
import java.util.Arrays;
import java.io.IOException;
import org.apache.commons.cli.*;


public class main {

public static void main(String[] args) {

    @SuppressWarnings("deprecation")
    CommandLineParser parser = new BasicParser();

    Options options = new Options();
    options.setArgs(Option.UNLIMITED_VALUES);   
    options.addOption("p", true, "Program under test");
    options.addOption("o", true, "Oracle");
    options.addOption("n", true, "Number of test cases");

    try {
        CommandLine commandline = parser.parse(options, args);

        System.out.println(commandline.getOptionValue("p"));

    } catch (ParseException e) {
        System.out.println("Command line failed.");
        e.printStackTrace();
    }

}

}

Solution

  • setArgs is a method related to Option not Options