List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:com.ibm.rdf.store.sparql11.DB2RDFQuery.java
public static void main(String[] args) { Options options = new Options(); try {//from w w w . jav a2s .c o m // create Options object options.addOption("jdbcurl", true, "jdbc url"); options.addOption("schema", true, "schema name"); options.addOption("kb", true, "knowledge base"); options.addOption("username", true, "db user name"); options.addOption("password", true, "db password"); options.addOption("queryFile", true, "query file"); options.addOption("defaultUnionGraph", false, "default Union Graph semantics"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); boolean defUnion = cmd.hasOption("defaultUnionGraph") ? Boolean.parseBoolean(cmd.getOptionValue("defaultUnionGraph")) : false; DB2TestData data = new DB2TestData(cmd.getOptionValue("jdbcurl"), cmd.getOptionValue("kb"), cmd.getOptionValue("username"), cmd.getOptionValue("password"), cmd.getOptionValue("schemaName"), defUnion); DB2RDFQuery q = new DB2RDFQuery(new DB2Engine(), data); q.executeQuery(cmd.getOptionValue("queryFile")); } catch (Exception e) { e.printStackTrace(); HelpFormatter help = new HelpFormatter(); help.printHelp("DB2RDFQuery", options); } }
From source file:com.google.cloud.logging.v2.LoggingSmokeTest.java
public static void main(String args[]) { Logger.getLogger("").setLevel(Level.WARNING); try {/*from ww w . j a v a 2s.co m*/ Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("project_id").desc("Project id").hasArg() .argName("PROJECT-ID").required(true).build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("LoggingSmokeTest", options); } executeNoCatch(cl.getOptionValue("project_id")); System.out.println("OK"); } catch (Exception e) { System.err.println("Failed with exception:"); e.printStackTrace(System.err); System.exit(1); } }
From source file:com.opensearchserver.affinities.Main.java
public static void main(String[] args) throws IOException, ParseException { Logger.getLogger("").setLevel(Level.WARNING); Options options = new Options(); options.addOption("h", "help", false, "print this message"); options.addOption("d", "datadir", true, "Data directory"); options.addOption("p", "port", true, "TCP port"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar target/oss-affinities.jar", options); return;/*from w w w. jav a 2s. c om*/ } int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9092; File dataDir = new File(System.getProperty("user.home"), "opensearchserver_affinities"); if (cmd.hasOption("d")) dataDir = new File(cmd.getOptionValue("d")); if (!dataDir.exists()) throw new IOException("The data directory does not exists: " + dataDir); if (!dataDir.isDirectory()) throw new IOException("The data directory path is not a directory: " + dataDir); AffinityList.load(dataDir); UndertowJaxrsServer server = new UndertowJaxrsServer() .start(Undertow.builder().addHttpListener(port, "0.0.0.0")); server.deploy(Main.class); }
From source file:com.bc.fiduceo.matchup.MatchupToolMain.java
public static void main(String[] args) throws ParseException, IOException, SQLException, InvalidRangeException { final MatchupTool matchupTool = new MatchupTool(); if (args.length == 0) { matchupTool.printUsageTo(System.err); return;/* ww w . j a va 2s . c o m*/ } final CommandLineParser parser = new PosixParser(); final CommandLine commandLine = parser.parse(MatchupTool.getOptions(), args); if (commandLine.hasOption("h") || commandLine.hasOption("--help")) { matchupTool.printUsageTo(System.err); return; } try { matchupTool.run(commandLine); } catch (Throwable e) { FiduceoLogger.getLogger().severe(e.getMessage()); e.printStackTrace(); System.exit(-1); } }
From source file:com.discursive.jccook.cmdline.SomeApp.java
public static void main(String[] args) throws Exception { // Create a Parser CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "help", false, "Print this usage information"); options.addOption("v", "verbose", false, "Print out VERBOSE information"); OptionGroup optionGroup = new OptionGroup(); optionGroup.addOption(OptionBuilder.hasArg(true).withArgName("file").withLongOpt("file").create('f')); optionGroup.addOption(OptionBuilder.hasArg(true).withArgName("email").withLongOpt("email").create('m')); options.addOptionGroup(optionGroup); // Parse the program arguments try {//from w w w .j a v a 2 s . c o m CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { printUsage(options); System.exit(0); } // ... do important stuff ... } catch (Exception e) { System.out.println("You provided bad program arguments!"); printUsage(options); System.exit(1); } }
From source file:com.bc.fiduceo.ingest.IngestionToolMain.java
public static void main(String[] args) throws ParseException, IOException, SQLException { final IngestionTool ingestionTool = new IngestionTool(); if (args.length == 0) { ingestionTool.printUsageTo(System.err); return;//from w w w.j a v a 2 s . com } final CommandLineParser parser = new PosixParser(); final CommandLine commandLine = parser.parse(IngestionTool.getOptions(), args); if (commandLine.hasOption("h") || commandLine.hasOption("--help")) { ingestionTool.printUsageTo(System.out); return; } try { ingestionTool.run(commandLine); } catch (Throwable e) { FiduceoLogger.getLogger().severe(e.getMessage()); e.printStackTrace(); System.exit(-1); } }
From source file:com.google.api.codegen.DiscoveryFragmentGeneratorTool.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("discovery_doc") .desc("The Discovery doc representing the service description.").hasArg().argName("DISCOVERY-DOC") .required(true).build());/*from ww w. j a v a 2s . com*/ options.addOption(Option.builder().longOpt("overrides").desc("The path to the sample config overrides file") .hasArg().argName("OVERRIDES").build()); options.addOption(Option.builder().longOpt("gapic_yaml").desc("The GAPIC YAML configuration file or files.") .hasArg().argName("GAPIC-YAML").required(true).build()); options.addOption(Option.builder("o").longOpt("output") .desc("The directory in which to output the generated fragments.").hasArg() .argName("OUTPUT-DIRECTORY").build()); options.addOption(Option.builder().longOpt("auth_instructions") .desc("An @-delimited map of language to auth instructions URL: lang:URL@lang:URL@...").hasArg() .argName("AUTH-INSTRUCTIONS").build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("CodeGeneratorTool", options); } generate(cl.getOptionValue("discovery_doc"), cl.getOptionValues("gapic_yaml"), cl.getOptionValue("overrides", ""), cl.getOptionValue("output", ""), cl.getOptionValue("auth_instructions", "")); }
From source file:edu.toronto.cs.cidb.obo2solr.Main.java
public static void main(String args[]) { Options options = generateOptions(); try {// w w w. j a v a 2s .com CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (!cmd.hasOption(OBO_DB_LOCATION_OPTION) || cmd.hasOption(HELP_OPTION)) { showUsage(options); System.exit(cmd.hasOption(HELP_OPTION) ? 0 : 1); } ParameterPreparer paramPrep = new ParameterPreparer(); SolrUpdateGenerator generator = new SolrUpdateGenerator(); File input = paramPrep.getInputFileHandler(cmd.getOptionValue(OBO_DB_LOCATION_OPTION)); File output = paramPrep.getOutputFileHandler( cmd.getOptionValue(OUTPUT_XML_LOCATION_OPTION, DEFAULT_OUTPUT_XML_LOCATION)); Map<String, Double> fieldSelection = paramPrep .getFieldSelection(cmd.getOptionValue(INDEX_FILEDS_OPTION, "")); generator.transform(input, output, fieldSelection); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:edu.toronto.cs.phenotips.obo2solr.Main.java
public static void main(String[] args) { Options options = generateOptions(); try {/*from w w w. ja v a 2 s. c o m*/ CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (!cmd.hasOption(OBO_DB_LOCATION_OPTION) || cmd.hasOption(HELP_OPTION)) { showUsage(options); System.exit(cmd.hasOption(HELP_OPTION) ? 0 : 1); } ParameterPreparer paramPrep = new ParameterPreparer(); SolrUpdateGenerator generator = new SolrUpdateGenerator(); File input = paramPrep.getInputFileHandler(cmd.getOptionValue(OBO_DB_LOCATION_OPTION)); File output = paramPrep.getOutputFileHandler( cmd.getOptionValue(OUTPUT_XML_LOCATION_OPTION, DEFAULT_OUTPUT_XML_LOCATION)); Map<String, Double> fieldSelection = paramPrep .getFieldSelection(cmd.getOptionValue(INDEX_FILEDS_OPTION, "")); generator.transform(input, output, fieldSelection); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceSmokeTest.java
public static void main(String args[]) { Logger.getLogger("").setLevel(Level.WARNING); try {//from w ww.j a va 2s . c o m Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("project_id").desc("Project id").hasArg() .argName("PROJECT-ID").required(true).build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("ReportErrorsServiceSmokeTest", options); } executeNoCatch(cl.getOptionValue("project_id")); System.out.println("OK"); } catch (Exception e) { System.err.println("Failed with exception:"); e.printStackTrace(System.err); System.exit(1); } }