Example usage for org.apache.commons.cli Option setRequired

List of usage examples for org.apache.commons.cli Option setRequired

Introduction

In this page you can find the example usage for org.apache.commons.cli Option setRequired.

Prototype

public void setRequired(boolean required) 

Source Link

Document

Sets whether this Option is mandatory.

Usage

From source file:it.iit.genomics.cru.genomics.misc.apps.Vcf2tabApp.java

public static void main(String[] args) throws IOException, ParseException {

    Options options = new Options();

    Option helpOpt = new Option("help", "print this message.");
    options.addOption(helpOpt);/*from w  w  w  .  jav  a 2  s.co m*/

    Option option1 = new Option("f", "filename", true, "VCF file to load");
    option1.setRequired(true);
    options.addOption(option1);

    option1 = new Option("o", "outputfile", true, "outputfilene");
    option1.setRequired(true);
    options.addOption(option1);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;

    try {
        // parse the command line arguments
        cmd = parser.parse(options, args, true);
    } catch (ParseException exp) {
        displayUsage("vcf2tab", options);
        System.exit(1);
    }
    if (cmd.hasOption("help")) {
        displayUsage("vcf2tab", options);
        System.exit(0);
    }

    String filename = cmd.getOptionValue("f");
    String outputfilename = cmd.getOptionValue("o");

    Vcf2tab loader = new Vcf2tab();

    loader.file2tab(filename, outputfilename); //(args[0]);

}

From source file:edu.mit.csail.sdg.alloy4.VizGUI.java

/**
 * @param args/*from ww  w  . ja  va2  s  . c  o m*/
 */
public static void main(String[] args) {
    // create the command line parser
    CommandLineParser parser = new PosixParser();

    // create the Options
    Options optionsArg = new Options();
    Option helpOpt = new Option("?", "help", false, "print this message");
    Option inputFileOpt = new Option("f", "file", true, "the name of the xml file to show");
    inputFileOpt.setRequired(true);

    optionsArg.addOption(helpOpt);
    optionsArg.addOption(inputFileOpt);

    CommandLine line = null;
    try {
        // parse the command line arguments
        line = parser.parse(optionsArg, args);

        if (line.hasOption(helpOpt.getOpt())) {
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("vizgui", optionsArg);
            return;
        }

    } catch (ParseException exp) {
        System.err.println("Unexpected exception:" + exp.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("vizgui", optionsArg);
        return;
    }

    String inputFile = null;
    if (line.hasOption(inputFileOpt.getOpt())) {
        inputFile = line.getOptionValue(inputFileOpt.getOpt());
        if (inputFile == null) {
            System.err.println("Invalid input file");
        }
    }

    new edu.mit.csail.sdg.alloy4viz.VizGUI(true, inputFile, null);

}

From source file:de.uni_koblenz.jgralabtest.non_junit_tests.TryCLI.java

/**
 * @param args// w w w . ja  v a 2 s  . c o  m
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    OptionHandler oh = new OptionHandler("TryCli", "version 0.0");

    // Option multipleValues = new Option("m", "multiple", true,
    // "Can occur multiple times.");
    // multipleValues.setRequired(true);
    // multipleValues.setArgName("arg");
    // multipleValues.setValueSeparator(',');
    // multipleValues.setArgs(Option.UNLIMITED_VALUES);

    // Option multipleValues2 = new Option("M", "Multiple", true,
    // "Can occur multiple times.");
    // multipleValues2.setRequired(false);
    // multipleValues2.setArgName("arg");
    // multipleValues2.setValueSeparator(',');
    // multipleValues2.setOptionalArg(true);
    // multipleValues2.setArgs(Option.UNLIMITED_VALUES);

    Option test = new Option("t", "test", false, "For testing purpose.");
    test.setRequired(false);
    oh.addOption(test);

    Option test2 = new Option("T", "Test", false, "For testing purpose.");
    test2.setRequired(false);
    oh.addOption(test2);

    OptionGroup og = new OptionGroup();
    og.addOption(test);
    og.addOption(test2);
    og.setRequired(true);
    oh.addOptionGroup(og);

    // oh.addOption(multipleValues);
    // oh.addOption(multipleValues2);

    CommandLine cmd = oh.parse(args);

    if (cmd.hasOption('t')) {
        System.out.println("Test1 set");
    }
    if (cmd.hasOption('T')) {
        System.out.println("Test2 set");
    }

}

From source file:com.example.dlp.Metadata.java

/** Retrieve infoTypes. */
public static void main(String[] args) throws Exception {
    Options options = new Options();
    Option languageCodeOption = new Option("language", null, true, "BCP-47 language code");
    languageCodeOption.setRequired(false);
    options.addOption(languageCodeOption);

    Option categoryOption = new Option("category", null, true, "Category of info types to list.");
    categoryOption.setRequired(false);// www.  jav  a 2 s . c o  m
    options.addOption(categoryOption);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp(Metadata.class.getName(), options);
        System.exit(1);
        return;
    }
    String languageCode = cmd.getOptionValue(languageCodeOption.getOpt(), "en-US");
    if (cmd.hasOption(categoryOption.getOpt())) {
        String category = cmd.getOptionValue(categoryOption.getOpt());
        listInfoTypes(category, languageCode);
    } else {
        listRootCategories(languageCode);
    }
}

From source file:net.robyf.dbpatcher.Launcher.java

public static void main(final String[] args) throws DBPatcherException { //NOSONAR
    Options options = new Options();

    Option usernameOption = new Option("u", "username", true, "Database username");
    usernameOption.setRequired(true);
    options.addOption(usernameOption);/*  w w w  .j  a va 2s .c o m*/
    Option passwordOption = new Option("p", "password", true, "Database password");
    passwordOption.setRequired(true);
    options.addOption(passwordOption);
    Option databaseOption = new Option("d", "databaseName", true, "Database name");
    databaseOption.setRequired(true);
    options.addOption(databaseOption);
    options.addOption("r", "rollback-if-error", false, "Rolls back the entire operation in case of errors");
    options.addOption("v", "to-version", true, "Target version number");
    options.addOption("s", "simulation", false, "Simulate the operation without touching the current database");
    options.addOption("c", "character-set", true, "Character set (default value: ISO-8859-1)");

    Parameters parameters = new Parameters();
    boolean showHelp = false;
    try {
        CommandLine commandLine = new PosixParser().parse(options, args);

        parameters.setUsername(commandLine.getOptionValue("u"));
        parameters.setPassword(commandLine.getOptionValue("p"));
        parameters.setDatabaseName(commandLine.getOptionValue("d"));

        parameters.setRollbackIfError(commandLine.hasOption("r"));
        parameters.setSimulationMode(commandLine.hasOption("s"));
        if (commandLine.hasOption("v")) {
            parameters.setTargetVersion(new Long(commandLine.getOptionValue("v")));
        }
        if (commandLine.hasOption("c")) {
            parameters.setCharset(Charset.forName(commandLine.getOptionValue("c")));
        }

        if (commandLine.getArgs().length == 1) {
            parameters.setSchemaPath(commandLine.getArgs()[0]);
        } else {
            showHelp = true;
        }
    } catch (ParseException pe) {
        showHelp = true;
    }

    if (showHelp) {
        new HelpFormatter().printHelp("java -jar dbpatcher.jar" + " -u username -p password -d database_name"
                + " [options] schema_root", "Available options:", options, "");
    } else {
        DBPatcherFactory.getDBPatcher().patch(parameters);
    }
}

From source file:de.htwg_konstanz.in.uce.hp.parallel.integration_test.TargetMock.java

public static void main(String[] args) throws IOException {
    CommandLineParser parser = new PosixParser();

    // create the Options
    Options options = new Options();
    Option o = new Option("m", "mediatorIP", true, "mediator ip");
    o.setRequired(true);
    options.addOption(o);/*  ww w . ja v  a2  s.c  o  m*/
    o = new Option("p", "mediatorPort", true, "mediator port");
    o.setRequired(true);
    options.addOption(o);
    o = new Option("t", "targetId", true, "target ID");
    o.setRequired(true);
    options.addOption(o);

    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("TargetMock", options);
        return;
    }

    String mediatorIP = cmd.getOptionValue("mediatorIP");
    String mediatorPort = cmd.getOptionValue("mediatorPort");
    String targetId = cmd.getOptionValue("targetId");

    InetSocketAddress mediatorSocketAddress;

    try {
        int port = Integer.parseInt(mediatorPort);
        mediatorSocketAddress = new InetSocketAddress(mediatorIP, port);
    } catch (NumberFormatException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("SourceMock", options);
        return;
    } catch (IllegalArgumentException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("SourceMock", options);
        return;
    }

    new TargetMock(mediatorSocketAddress, targetId).start();
}

From source file:com.genentech.chemistry.openEye.apps.SDFRingSystemExtractor.java

/**
 * @param args//from ww w .j a  v a2  s.c o m
 */
public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option(OPT_INFILE, true, "input file oe-supported");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option(OPT_OUTFILE, true, "output file oe-supported");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    String inFile = cmd.getOptionValue(OPT_INFILE);
    String outFile = cmd.getOptionValue(OPT_OUTFILE);
    SDFRingSystemExtractor extractor = new SDFRingSystemExtractor(outFile);
    extractor.run(inFile);
    extractor.close();
}

From source file:com.aestel.chemistry.openEye.fp.DistMatrix.java

public static void main(String... args) throws IOException {
    long start = System.currentTimeMillis();

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("i", true, "input file [.tsv from FingerPrinter]");
    opt.setRequired(true);
    options.addOption(opt);/*from   www.j  av a2s .  c  o m*/

    opt = new Option("o", true, "outpur file [.tsv ");
    opt.setRequired(true);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (args.length != 0)
        exitWithHelp(options);

    String file = cmd.getOptionValue("i");
    BufferedReader in = new BufferedReader(new FileReader(file));

    file = cmd.getOptionValue("o");
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)));

    ArrayList<Fingerprint> fps = new ArrayList<Fingerprint>();
    ArrayList<String> ids = new ArrayList<String>();
    String line;
    while ((line = in.readLine()) != null) {
        String[] parts = line.split("\t");
        if (parts.length == 3) {
            ids.add(parts[0]);
            fps.add(new ByteFingerprint(parts[2]));
        }
    }
    in.close();

    out.print("ID");
    for (int i = 0; i < ids.size(); i++) {
        out.print('\t');
        out.print(ids.get(i));
    }
    out.println();

    for (int i = 0; i < ids.size(); i++) {
        out.print(ids.get(i));
        Fingerprint fp1 = fps.get(i);

        for (int j = 0; j <= i; j++) {
            out.printf("\t%.4g", fp1.tanimoto(fps.get(j)));
        }
        out.println();
    }
    out.close();

    System.err.printf("Done %d fingerprints in %.2gsec\n", fps.size(),
            (System.currentTimeMillis() - start) / 1000D);
}

From source file:eu.edisonproject.utility.execute.Main.java

public static void main(String args[]) {
    Options options = new Options();
    Option operation = new Option("op", "operation", true,
            "type of operation to perform. " + "To move cached terms from org.mapdb.DB 'm'");
    operation.setRequired(true);
    options.addOption(operation);/*  w w w.ja va2  s .  c  o m*/

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(true);
    options.addOption(input);

    String helpmasg = "Usage: \n";
    for (Object obj : options.getOptions()) {
        Option op = (Option) obj;
        helpmasg += op.getOpt() + ", " + op.getLongOpt() + "\t Required: " + op.isRequired() + "\t\t"
                + op.getDescription() + "\n";
    }

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        switch (cmd.getOptionValue("operation")) {
        case "m":
            DBTools.portTermCache2Hbase(cmd.getOptionValue("input"));
            DBTools.portBabelNetCache2Hbase(cmd.getOptionValue("input"));
            break;
        default:
            System.out.println(helpmasg);
        }

    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, helpmasg, ex);
    }
}

From source file:com.blackducksoftware.tools.vuln_collector.VCRunner.java

public static void main(String[] args) throws Exception {
    System.out.println(TITLE);/*from w  w  w.  j a v  a  2 s  .  co m*/
    CommandLineParser parser = new DefaultParser();

    options.addOption("h", "help", false, "show help.");

    Option projectNameOption = new Option("projectName", true, "Name of Project (optional)");
    projectNameOption.setRequired(false);
    options.addOption(projectNameOption);

    Option configFileOption = new Option("config", true, "Location of configuration file (required)");
    configFileOption.setRequired(true);
    options.addOption(configFileOption);

    try {

        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h"))
            help();

        String[] projectNameList = null;
        File configFile = null;

        if (cmd.hasOption(VCConstants.CL_PROJECT_NAME)) {
            String projectName = cmd.getOptionValue(VCConstants.CL_PROJECT_NAME);
            log.info("Project name: " + projectName);
            // Could be a single project or comma delim
            projectNameList = VCProcessor.getProjectList(projectName);
        }

        // Config File
        if (cmd.hasOption(VCConstants.CL_CONFIG)) {
            String configFilePath = cmd.getOptionValue(VCConstants.CL_CONFIG);
            log.info("Config file location: " + configFilePath);
            configFile = new File(configFilePath);
            if (!configFile.exists()) {
                log.error("Configuration file does not exist at location: " + configFile);
                System.exit(-1);
            }
        } else {
            log.error("Must specify configuration file!");
            help();
        }

        VCProcessor processor = new VCProcessor(configFile.toString(), projectNameList);
        processor.processReport();

    } catch (ParseException e) {
        log.error("Error parsing: " + e.getMessage());
        help();
    } catch (Exception e) {
        log.error("General error: " + e.getMessage());

    }

}