Example usage for org.apache.commons.cli OptionBuilder hasArgs

List of usage examples for org.apache.commons.cli OptionBuilder hasArgs

Introduction

In this page you can find the example usage for org.apache.commons.cli OptionBuilder hasArgs.

Prototype

public static OptionBuilder hasArgs(int num) 

Source Link

Document

The next Option created can have num argument values.

Usage

From source file:com.rockagen.commons.util.CLITest.java

@Test
@Ignore//  w ww .  ja  v  a 2 s .c o m
public void testCLI() {

    // create the Options
    Options options = new Options();
    options.addOption("h", "help", false, "print help for the command.");
    options.addOption("v", "verbose", false, "verbose");
    OptionBuilder.withArgName("property=value");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withLongOpt("desc");
    OptionBuilder.withValueSeparator();
    OptionBuilder.withDescription("use value for given property");
    options.addOption(OptionBuilder.create("D"));

    OptionBuilder.withArgName("file1,file2...");
    OptionBuilder.hasArgs();
    OptionBuilder.withLongOpt("input");
    OptionBuilder.withValueSeparator(' ');
    OptionBuilder.withDescription("file name");
    options.addOption(OptionBuilder.create("i"));

    String formatstr = "CLITest [-h/--help][-v/--verbose]..";
    try {
        String[] args = { "CLITest", "--help", "-v", "-s", "--desc", "name=value", "--input", "file1", "file2",
                "file3" };
        // parse the command line arguments
        CommandLine line = CmdUtil.parse(options, args);

        if (line.hasOption("h")) {
            CmdUtil.printHelp(formatstr, "weclome usa", options,
                    "If you hava some quesion,please mail to agen@rockagen.com");
        }
        if (line.hasOption("v")) {
            System.out.println("VERSION 0.0.1");
        }
        if (line.hasOption("D")) {
            System.out.println("hey,guys,you input " + ArrayUtil.toString(line.getOptionValues("D")));
        }
        if (line.hasOption("i")) {
            System.out.println("hey,guys,you input " + ArrayUtil.toString(line.getOptionValues("i")));
        } else {
            CmdUtil.printHelp(formatstr, options);
        }
    } catch (ParseException exp) {
        CmdUtil.printHelp(formatstr, options);
        System.err.println();
        System.err.println(exp.getMessage());
    }

}

From source file:eu.alpinweiss.filegen.config.FdrOptionHolderImpl.java

@SuppressWarnings("static-access")
private void initOptions(Set<FdrStep> fdrSteps) {
    for (FdrStep fdrStep : fdrSteps) {
        options.addOption(OptionBuilder.hasArgs(1).hasOptionalArgs(1).isRequired(fdrStep.getRequired())
                .withValueSeparator(' ').withDescription(fdrStep.getDescription())
                .create(fdrStep.getCommand()));
        //         options.addOption(fdrStep.getCommand(), fdrStep.getRequired(), fdrStep.getDescription());
        commandSteps.put(fdrStep.getCommand(), getClassByClassName(fdrStep));
    }//  ww  w.jav  a2 s .c om
}

From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.spi.CliOptionsBuilder.java

public CliOptionsBuilder hasArgs(int num) {
    OptionBuilder.hasArgs(num);
    return this;
}

From source file:consumer.kafka.client.Consumer.java

private void init(String[] args) throws Exception {

    Options options = new Options();
    this._props = new Properties();

    options.addOption("p", true, "properties filename from the classpath");
    options.addOption("P", true, "external properties filename");

    OptionBuilder.withArgName("property=value");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withValueSeparator();//from   w w w  .  ja  va2 s.  c o  m
    OptionBuilder.withDescription("use value for given property");
    options.addOption(OptionBuilder.create("D"));

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption('p')) {
        this._props.load(ClassLoader.getSystemClassLoader().getResourceAsStream(cmd.getOptionValue('p')));
    }
    if (cmd.hasOption('P')) {
        File file = new File(cmd.getOptionValue('P'));
        FileInputStream fStream = new FileInputStream(file);
        this._props.load(fStream);
    }
    this._props.putAll(cmd.getOptionProperties("D"));

}

From source file:com.necla.simba.server.gateway.Main.java

public Main(String[] args) {
    options.addOption("h", "help", false, "print help message");
    options.addOption(OptionBuilder.hasArgs(1).withLongOpt("properties")
            .withDescription("Gateway properties file, this overrides default properties")
            .withType(String.class).create("p"));
    options.addOption(OptionBuilder.hasArgs(1).withLongOpt("port").withDescription("client communication port")
            .withType(Number.class).create("o"));
    CommandLineParser parser = new org.apache.commons.cli.BasicParser();
    try {//from  w w w.  ja  va  2s  .  c  o  m
        properties = new Properties();
        properties.put("port", 9000);

        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help"))
            usage();
        properties.load(Main.class.getResourceAsStream("/gateway.properties"));
        if (line.hasOption("properties"))
            properties.load(new FileInputStream(line.getOptionValue("properties")));
        if (line.hasOption("port"))
            properties.put("port", Integer.parseInt(line.getOptionValue("port")));
        // dump all notification info
    } catch (ParseException e) {
        usage();
    } catch (IOException e) {
        LOG.error("Could not load properties: " + e.getMessage());
        System.exit(1);
    }
}

From source file:com.necla.simba.server.simbastore.Main.java

public Main(String[] args) {
    options.addOption("h", "help", false, "print help message");
    options.addOption(OptionBuilder.hasArgs(1).withLongOpt("properties")
            .withDescription("SimbaStore properties file, this overrides default properties")
            .withType(String.class).create("p"));
    CommandLineParser parser = new org.apache.commons.cli.BasicParser();
    try {//from   w ww .j  a  v  a 2  s  . c  om
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help"))
            usage();
        properties = new Properties();
        properties.load(Main.class.getResourceAsStream("/simbastore.properties"));
        if (line.hasOption("properties"))
            properties.load(new FileInputStream(line.getOptionValue("properties")));
    } catch (ParseException e) {
        usage();
    } catch (IOException e) {
        LOG.error("Could not load properties: " + e.getMessage());
        System.exit(1);
    }

    IOStats.start();
    BackendStats.start();
}

From source file:be.svlandeg.diffany.console.DiffanyOptions.java

/**
 * Define the options specifying necessary arguments for the Diffany algorithms
 */// w w  w  . j  a v  a  2  s  . c  o  m
private Set<Option> getAllParameters() {
    Set<Option> allParameters = new HashSet<Option>();

    OptionBuilder.withArgName("dir");
    OptionBuilder.withLongOpt("inputDir");
    OptionBuilder.hasArgs(1);
    OptionBuilder.isRequired();
    OptionBuilder
            .withDescription("the input directory containing the reference and condition-specific networks");
    allParameters.add(OptionBuilder.create(inputShort));

    OptionBuilder.withArgName("dir");
    OptionBuilder.withLongOpt("outputDir");
    OptionBuilder.hasArgs(1);
    OptionBuilder.isRequired();
    OptionBuilder.withDescription(
            "the output directory which will contain the generated differential/consensus networks");
    allParameters.add(OptionBuilder.create(outputShort));

    String defaultRunDiffString = defaultRunDiff ? "yes" : "no";
    OptionBuilder.withLongOpt("differential");
    OptionBuilder.hasArgs(1);
    OptionBuilder.withDescription("whether or not to calculate differential networks: yes or no (default="
            + defaultRunDiffString + ")");
    allParameters.add(OptionBuilder.create(runDiff));

    String defaultRunConsString = defaultRunCons ? "yes" : "no";
    ;
    OptionBuilder.withLongOpt("consensus");
    OptionBuilder.hasArgs(1);
    OptionBuilder.withDescription(
            "whether or not to calculate consensus networks: yes or no (default=" + defaultRunConsString + ")");
    allParameters.add(OptionBuilder.create(runCons));

    OptionBuilder.withLongOpt("outputID");
    OptionBuilder.hasArgs(1);
    OptionBuilder.withDescription("the first ID that will be used for the generated networks");
    allParameters.add(OptionBuilder.create(nextID));

    OptionBuilder.withLongOpt("confidence");
    OptionBuilder.hasArgs(1);
    OptionBuilder.withDescription(
            "the minimum confidence threshold for output edges, as an integer or double (default=0.0)");
    allParameters.add(OptionBuilder.create(cutoffShort));

    String defaultMinOperatorString = defaultMinOperator ? "min" : "max";
    OptionBuilder.withLongOpt("operator");
    OptionBuilder.hasArgs(1);
    OptionBuilder.withDescription("the operator used to create consensus edges: min or max (default="
            + defaultMinOperatorString + ")");
    allParameters.add(OptionBuilder.create(operatorShort));

    String defaultModeString = defaultModePairwise ? "pairwise" : "all";
    OptionBuilder.withLongOpt("mode");
    OptionBuilder.hasArgs(1);
    OptionBuilder
            .withDescription("the mode of comparison: pairwise or all (default=" + defaultModeString + ")");
    allParameters.add(OptionBuilder.create(modeShort));

    String defaultHeaderString = defaultReadHeader ? "yes" : "no";
    OptionBuilder.withLongOpt("skipHeader");
    OptionBuilder.hasArgs(1);
    OptionBuilder.withDescription(
            "whether or not to skip the first line (header) in the network .txt files (default="
                    + defaultHeaderString + ")");
    allParameters.add(OptionBuilder.create(headerShort));

    return allParameters;
}

From source file:com.alibaba.jstorm.flux.Flux.java

private static Option option(int argCount, String shortName, String longName, String argName,
        String description) {/* ww w .  j  av  a2 s . com*/
    Option option = OptionBuilder.hasArgs(argCount).withArgName(argName).withLongOpt(longName)
            .withDescription(description).create(shortName);
    return option;
}

From source file:com.conversantmedia.mapreduce.tool.AnnotatedToolContext.java

@SuppressWarnings("static-access")
private org.apache.commons.cli.Option initOption(Options options, Option anno, String optName) {
    OptionBuilder.withLongOpt(optName).withArgName(getValue(anno.argName()))
            .withDescription(getValue(anno.description())).isRequired(anno.required());

    if (anno.argCount() > 0) {
        OptionBuilder.hasArgs(anno.argCount());
    }//from  w w  w  .j  av  a  2 s .  c om

    return OptionBuilder.create();
}

From source file:cn.edu.pku.cbi.mosaichunter.MosaicHunter.java

private static boolean loadConfiguration(String[] args, String configFile) throws Exception {
    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();//from  ww w. j  a  v  a 2  s.  co m
    OptionBuilder.withDescription("config file");
    OptionBuilder.withLongOpt("config");
    Option configFileOption = OptionBuilder.create("C");

    OptionBuilder.withArgName("property=value");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withValueSeparator();
    OptionBuilder.withDescription("properties that overrides the ones in config file");
    OptionBuilder.withLongOpt("properties");
    Option propertiesOption = OptionBuilder.create("P");

    Options options = new Options();
    options.addOption(configFileOption);
    options.addOption(propertiesOption);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException pe) {
        System.out.println(pe.getMessage());
        return false;
    }

    InputStream in = null;

    if (configFile == null || configFile.trim().isEmpty()) {
        configFile = cmd.getOptionValue("C");
        if (configFile != null && new File(configFile).isFile()) {
            in = new FileInputStream(configFile);
        }
    } else {
        in = MosaicHunter.class.getClassLoader().getResourceAsStream(configFile);
    }
    if (in != null) {
        try {
            ConfigManager.getInstance().loadProperties(in);
        } catch (IOException ioe) {
            System.out.println("invalid config file: " + configFile);
            return false;
        } finally {
            in.close();
        }
    }

    Properties properties = cmd.getOptionProperties("P");
    if (properties != null) {
        ConfigManager.getInstance().putAll(properties);
    }

    return !ConfigManager.getInstance().getProperties().isEmpty();
}