Example usage for org.apache.commons.cli CommandLine hasOption

List of usage examples for org.apache.commons.cli CommandLine hasOption

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine hasOption.

Prototype

public boolean hasOption(char opt) 

Source Link

Document

Query to see if an option has been set.

Usage

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

/**
 * @param args//from w ww  .  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:fr.tpt.atlanalyser.tests.TestClass2RelationalPost2Pre.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {

    // URL resource = Thread.currentThread().getContextClassLoader()
    // .getResource("OldAGTExp");
    // System.out.println(resource.toString());
    // File f = new File(resource.getPath());
    // System.out.println(f.toString());
    // System.out.println(f.isDirectory());
    // System.exit(0);

    Options options = new Options();
    options.addOption(//  w  w w.  j av  a  2  s  . c  o m
            OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j"));
    options.addOption(OptionBuilder.withDescription("Display help").create("h"));

    CommandLineParser parser = new BasicParser();
    int jobs = 2;
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            new HelpFormatter().printHelp(TestClass2RelationalPost2Pre.class.getSimpleName(), options);
            System.exit(0);
        }

        if (cmd.hasOption("j")) {
            jobs = Integer.parseInt(cmd.getOptionValue("j"));
        }
    } catch (Exception e) {
        System.out.println("Incorrect command line arguments");
        new HelpFormatter().printHelp(TestClass2RelationalPost2Pre.class.getSimpleName(), options);
        System.exit(1);
    }

    new TestClass2RelationalPost2Pre(models().get(0)[0], jobs).testPost2Pre();
}

From source file:fr.tpt.atlanalyser.tests.TestForPaperPost2Pre.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {

    // URL resource = Thread.currentThread().getContextClassLoader()
    // .getResource("OldAGTExp");
    // System.out.println(resource.toString());
    // File f = new File(resource.getPath());
    // System.out.println(f.toString());
    // System.out.println(f.isDirectory());
    // System.exit(0);

    Options options = new Options();
    options.addOption(/*  www. j  a  v a2 s  .  c  om*/
            OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j"));
    options.addOption(OptionBuilder.withDescription("Display help").create("h"));

    CommandLineParser parser = new BasicParser();
    int jobs = 1;
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            new HelpFormatter().printHelp(TestForPaperPost2Pre.class.getSimpleName(), options);
            System.exit(0);
        }

        if (cmd.hasOption("j")) {
            jobs = Integer.parseInt(cmd.getOptionValue("j"));
        }
    } catch (Exception e) {
        System.out.println("Incorrect command line arguments");
        new HelpFormatter().printHelp(TestForPaperPost2Pre.class.getSimpleName(), options);
        System.exit(1);
    }

    new TestForPaperPost2Pre(models().get(0)[0], jobs).testPost2Pre();
}

From source file:fr.tpt.atlanalyser.tests.TestPointsToLinesPost2Pre.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException {

    // URL resource = Thread.currentThread().getContextClassLoader()
    // .getResource("OldAGTExp");
    // System.out.println(resource.toString());
    // File f = new File(resource.getPath());
    // System.out.println(f.toString());
    // System.out.println(f.isDirectory());
    // System.exit(0);

    Options options = new Options();
    options.addOption(//  w  w  w  .  j  ava  2s.co  m
            OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j"));
    options.addOption(OptionBuilder.withDescription("Display help").create("h"));

    CommandLineParser parser = new BasicParser();
    int jobs = 1;
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            new HelpFormatter().printHelp(TestPointsToLinesPost2Pre.class.getSimpleName(), options);
            System.exit(0);
        }

        if (cmd.hasOption("j")) {
            jobs = Integer.parseInt(cmd.getOptionValue("j"));
        }
    } catch (Exception e) {
        System.out.println("Incorrect command line arguments");
        new HelpFormatter().printHelp(TestPointsToLinesPost2Pre.class.getSimpleName(), options);
        System.exit(1);
    }

    new TestPointsToLinesPost2Pre(models().get(1)[0], jobs).testPost2Pre();
}

From source file:com.ovea.tajin.server.ContainerRunner.java

public static void main(String... args) throws Exception {
    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(options, args);

    if (line.hasOption("help") || !line.hasOption(Properties.CONTAINER.getName())) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ContainerRunner.class.getSimpleName(), options);
        return;/*  w  ww  . j  a  v  a  2s.co m*/
    }

    // Set default values
    // And override by system properties. This way, we can start ContainerRunner with specific options such as -DjettyConf=.. -DjettyEnv=...
    ContainerConfiguration settings = ContainerConfiguration.from(System.getProperties());
    // Then parse command line
    for (Option option : line.getOptions()) {
        settings.set(Properties.from(option.getOpt()), line.getOptionValue(option.getOpt()));
    }
    Container container = settings.buildContainer(line.getOptionValue(Properties.CONTAINER.getName()));
    container.start();
}

From source file:com.tomdoel.mpg2dcm.Xml2Dicom.java

public static void main(String[] args) {
    try {//from ww w .  j  a v a 2  s.  c om
        final Options helpOptions = new Options();
        helpOptions.addOption("h", false, "Print help for this application");

        final DefaultParser parser = new DefaultParser();
        final CommandLine commandLine = parser.parse(helpOptions, args);

        if (commandLine.hasOption('h')) {
            final String helpHeader = "Converts an endoscopic xml and video files to Dicom\n\n";
            String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm";

            final HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("Xml2Dcm xml-file dicom-output-path", helpHeader, helpOptions, helpFooter,
                    true);

        } else {
            final List<String> remainingArgs = commandLine.getArgList();
            if (remainingArgs.size() < 2) {
                throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified.");
            }

            final String xmlInputFileName = remainingArgs.get(0);
            final String dicomOutputPath = remainingArgs.get(1);
            EndoscopicXmlToDicomConverter.convert(new File(xmlInputFileName), dicomOutputPath);
        }
    } catch (org.apache.commons.cli.ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:de.fischer.thotti.core.runner.TargetURLGenerator.java

public static final void main(String[] args) {
    String accessKey = null;/*from  www  . ja va2  s.c  om*/
    String secretKey = null;

    Options options = createCommandLineOption();

    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (!line.hasOption("ak")) {
            throw new ParseException("AWS Accress Key is missing.");
        }

        if (!line.hasOption("sk")) {
            throw new ParseException("AWS Secret Key is missing.");
        }

        accessKey = line.getOptionValue("ak");
        secretKey = line.getOptionValue("sk");

    } catch (ParseException exp) {
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        System.exit(1);
    }

    TargetURLGenerator generator = new TargetURLGenerator();

    generator.setAccessKey(accessKey);
    generator.setSecretKey(secretKey);

    generator.run();
}

From source file:di.uniba.it.tee2.search.Search.java

/**
 * language maindir query temp_query//  w  w w  .  j  a va  2  s  .c o  m
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    try {
        CommandLine cmd = cmdParser.parse(options, args);
        if (cmd.hasOption("l") && cmd.hasOption("d") && cmd.hasOption("q")) {
            try {
                TemporalExtractor te = new TemporalExtractor(cmd.getOptionValue("l"));
                te.init();
                TemporalEventSearch search = new TemporalEventSearch(cmd.getOptionValue("d"), te);
                search.init();
                List<SearchResult> res = search.search(cmd.getOptionValue("q"), cmd.getOptionValue("t", ""),
                        100);
                for (SearchResult r : res) {
                    System.out.println(r);
                }
                search.close();
                te.close();
            } catch (Exception ex) {
                Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.printHelp("Run searching", options, true);
        }
    } catch (ParseException ex) {
        Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:edu.umass.cs.gnsclient.console.CommandLineInterface.java

/**
 * Starts the GNS command line interface (CLI) console
 *
 * @param args optional argument is -silent for no console output
 * @throws Exception/*  w w  w. j av  a 2 s.com*/
 */
public static void main(String[] args) throws Exception {
    try {
        CommandLine parser = initializeOptions(args);
        if (parser.hasOption("help")) {
            printUsage();
            //System.out.println("-host and -port are required!");
            System.exit(1);
        }
        boolean silent = parser.hasOption("silent");
        boolean noDefaults = parser.hasOption("noDefaults");
        ConsoleReader consoleReader = new ConsoleReader(System.in, new PrintWriter(System.out, true));
        ConsoleModule module = new ConsoleModule(consoleReader);
        if (noDefaults) {
            module.setUseGnsDefaults(false);
            KeyPairUtils.removeDefaultGns();
        }
        module.setSilent(silent);
        if (!silent) {
            module.printString("GNS Client Version: " + GNSClientConfig.readBuildVersion() + "\n");
        }
        module.handlePrompt();
        System.exit(0);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:net.librec.tool.driver.DataDriver.java

public static void main(String[] args) throws Exception {
    LibrecTool tool = new DataDriver();

    Options options = new Options();
    options.addOption("build", false, "build model");
    options.addOption("load", false, "load model");
    options.addOption("save", false, "save model");
    options.addOption("conf", true, "the path of configuration file");
    options.addOption("jobconf", true, "a specified key-value pair for configuration");
    options.addOption("D", true, "a specified key-value pair for configuration");

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

    if (cmd.hasOption("build")) {
        tool.run(args);//from w  w w  . j  a v  a 2  s  . com
    } else if (cmd.hasOption("load")) {
        ;
    } else if (cmd.hasOption("save")) {
        ;
    }
}