List of usage examples for org.apache.commons.cli CommandLineParser parse
CommandLine parse(Options options, String[] arguments) throws ParseException;
From source file:com.linkedin.restli.tools.snapshot.gen.RestLiSnapshotExporterCmdLineApp.java
/** * @param args restliexporter -sourcepath sourcepath -resourcepackages packagenames [-name api_name] [-outdir outdir] */// w ww . j av a2 s.com public static void main(String[] args) { CommandLine cl = null; try { final CommandLineParser parser = new GnuParser(); cl = parser.parse(OPTIONS, args); } catch (ParseException e) { System.err.println("Invalid arguments: " + e.getMessage()); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "restliexporter -sourcepath sourcepath [-resourcepackages packagenames] [-resourceclasses classnames]" + "[-name api_name] [-outdir outdir]", OPTIONS); System.exit(0); } final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH); try { final RestLiSnapshotExporter exporter = new RestLiSnapshotExporter(); exporter.setResolverPath(resolverPath); exporter.export(cl.getOptionValue("name"), null, cl.getOptionValues("sourcepath"), cl.getOptionValues("resourcepackages"), cl.getOptionValues("resourceClasses"), cl.getOptionValue("outdir", "."), AdditionalDocProvidersUtil.findDocProviders(log, cl.hasOption("loadAdditionalDocProviders"))); } catch (Throwable e) { log.error("Error writing Snapshot files", e); System.out.println("Error writing Snapshot files:\n" + e); System.exit(1); } }
From source file:eu.scape_project.tb.lsdr.seqfileutility.SequenceFileUtility.java
/** * Main method//from www . j av a 2s . c o m * @param args Command line arguments * @throws Exception */ public static void main(String args[]) throws Exception { int res = 1; Configuration conf = new Configuration(); //conf.set("mapred.max.split.size", "16777216"); //conf.setBoolean("mapreduce.client.genericoptionsparser.used", false); GenericOptionsParser gop = new GenericOptionsParser(conf, args); ProcessParameters pc = new ProcessParameters(); CommandLineParser cmdParser = new PosixParser(); CommandLine cmd = cmdParser.parse(Options.OPTIONS, gop.getRemainingArgs()); if ((args.length == 0) || (cmd.hasOption(Options.HELP_OPT))) { Options.exit("Usage", 0); } else { Options.initOptions(cmd, pc); eu.scape_project.tb.lsdr.seqfileutility.Job j; if (!pc.isHadoopmapmode()) { j = new BatchJob(pc); j.run(); res = 0; } else { HadoopJob hj = new HadoopJob(); hj.setPc(pc); res = ToolRunner.run(conf, hj, args); if (res == 0) System.out.print(pc.getOutputDirectory()); } } System.exit(res); }
From source file:fr.jamgotchian.tuplegen.core.Main.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); try {//from w ww . jav a 2 s . c o m CommandLine line = parser.parse(OPTIONS, args); if (line.hasOption("h") || !line.hasOption("c") || !line.hasOption("d")) { usage(); } File genSrcDir = new File(line.getOptionValue("d")); if (!genSrcDir.exists()) { throw new IllegalArgumentException(genSrcDir + " does not exit"); } if (!genSrcDir.isDirectory()) { throw new IllegalArgumentException(genSrcDir + " should be a directory"); } File cfgFile = new File(line.getOptionValue("c")); if (!cfgFile.exists()) { throw new IllegalArgumentException(cfgFile + " does not exist"); } TupleGen generator = new TupleGen(); generator.generate(cfgFile, genSrcDir, false, LOGGER); } catch (Throwable t) { t.printStackTrace(); } }
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);/* w w w . j a v a 2 s . c o m*/ } else if (cmd.hasOption("load")) { ; } else if (cmd.hasOption("save")) { ; } }
From source file:com.google.infrastructuredmap.MapAndMarkdownExtractorMain.java
public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); options.addOption(ARG_KML, true, "path to KML input"); options.addOption(ARG_MARKDOWN, true, "path to Markdown input"); options.addOption(ARG_JSON_OUTPUT, true, "path to write json output"); options.addOption(ARG_JSONP, true, "JSONP template to wrap output JSON data"); CommandLineParser parser = new DefaultParser(); CommandLine cli = parser.parse(options, args); // Extract map features from the input KML. MapData data = null;/*from w w w. ja v a 2s. c om*/ try (InputStream in = openStream(cli.getOptionValue(ARG_KML))) { Kml kml = Kml.unmarshal(in); data = MapDataExtractor.extractMapData(kml); } // Extract project features from the input Markdown. Map<String, List<ProjectReference>> references = MarkdownReferenceExtractor .extractReferences(Paths.get(cli.getOptionValue(ARG_MARKDOWN))); for (MapFeature feature : data.features) { List<ProjectReference> referencesForId = references.get(feature.id); if (referencesForId == null) { throw new IllegalStateException("Unknown project reference: " + feature.id); } feature.projects = referencesForId; } // Write the resulting data to the output path. Gson gson = new Gson(); try (FileWriter out = new FileWriter(cli.getOptionValue(ARG_JSON_OUTPUT))) { String json = gson.toJson(data); if (cli.hasOption(ARG_JSONP)) { json = String.format(cli.getOptionValue(ARG_JSONP), json); } out.write(json); } }
From source file:com.uber.tchannel.ping.PingClient.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "host", true, "Server Host to connect to"); options.addOption("p", "port", true, "Server Port to connect to"); options.addOption("n", "requests", true, "Number of requests to make"); options.addOption("?", "help", false, "Usage"); HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("?")) { formatter.printHelp("PingClient", options, true); return;/*from w w w . ja va2 s . c o m*/ } String host = cmd.getOptionValue("h", "localhost"); int port = Integer.parseInt(cmd.getOptionValue("p", "8888")); int requests = Integer.parseInt(cmd.getOptionValue("n", "10000")); System.out.println(String.format("Connecting from client to server on port: %d", port)); new PingClient(host, port, requests).run(); System.out.println("Stopping Client..."); }
From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.Pipeline.java
public static void main(String[] args) throws Exception { DATASET_DIR = DKProContext.getContext().getWorkspace().getAbsolutePath() + "/Datasets/###/ds"; GOLDSTANDARD_DIR = DKProContext.getContext().getWorkspace().getAbsolutePath() + "/Datasets/###/gs"; Options options = new Options(); options.addOption("d", "dataset", true, "dataset to evaluate: " + StringUtils.join(Dataset.values(), ", ")); options.addOption("c", "classifier", true, "classifier to use: " + StringUtils.join(WekaClassifier.values(), ", ")); CommandLineParser parser = new PosixParser(); try {//from ww w . ja v a 2s. c om CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("d") && cmd.hasOption("c")) { Dataset dataset = Dataset.valueOf(cmd.getOptionValue("d")); WekaClassifier wekaClassifier = WekaClassifier.valueOf(cmd.getOptionValue("c")); runCV(dataset, wekaClassifier); } else { new HelpFormatter().printHelp(Pipeline.class.getSimpleName(), options, true); } } catch (ParseException e) { new HelpFormatter().printHelp(Pipeline.class.getSimpleName(), options); } }
From source file:com.contentful.generator.Main.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); Options options = constructOptions(); try {/* w w w . j av a 2 s . c o m*/ CommandLine line = parser.parse(options, args); if (line.hasOption("space") && line.hasOption("package") && line.hasOption("folder") && line.hasOption("token")) { new Generator().generate(line.getOptionValue("space"), line.getOptionValue("package"), line.getOptionValue("folder"), line.getOptionValue("token")); } else { usage(options); } } catch (ParseException e) { System.err.println("Parsing failed, reason: " + e.getMessage()); } }
From source file:com.linkedin.restli.tools.idlgen.RestLiResourceModelExporterCmdLineApp.java
/** * @param args restliexporter -sourcepath sourcepath -resourcepackages packagenames [-name api_name] [-outdir outdir] *//* w w w . j av a 2 s. co m*/ public static void main(String[] args) { // args = new String[] {"-name", "groups", // "-resourcepackages", "com.linkedin.groups.server.rest1.impl com.linkedin.groups.server.rest2.impl ", // "-resourceclasses", "com.linkedin.groups.server.restX.impl.FooResource", // "-sourcepath", "src/main/java", // "-outdir", "src/codegen/idl", // "-split"}; CommandLine cl = null; try { final CommandLineParser parser = new GnuParser(); cl = parser.parse(OPTIONS, args); } catch (ParseException e) { System.err.println("Invalid arguments: " + e.getMessage()); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "restliexporter -sourcepath sourcepath [-resourcepackages packagenames] [-resourceclasses classnames]" + "[-name api_name] [-outdir outdir]", OPTIONS); System.exit(0); } try { new RestLiResourceModelExporter().export(cl.getOptionValue("name"), null, cl.getOptionValues("sourcepath"), cl.getOptionValues("resourcepackages"), cl.getOptionValues("resourceclasses"), cl.getOptionValue("outdir", "."), AdditionalDocProvidersUtil.findDocProviders(log, cl.hasOption("loadAdditionalDocProviders"))); } catch (Throwable e) { log.error("Error writing IDL files", e); System.exit(1); } }
From source file:com.basingwerk.utilisation.Utilisation.java
public static void main(final String[] args) { String dataFile = null;/*from w w w . ja v a 2 s. com*/ Options options = new Options(); Option helpOption = new Option("h", "help", false, "print this help"); Option serverURLOption = new Option("l", "logfile", true, "log file"); options.addOption(helpOption); options.addOption(serverURLOption); CommandLineParser argsParser = new PosixParser(); try { CommandLine commandLine = argsParser.parse(options, args); if (commandLine.hasOption(helpOption.getOpt())) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Usage grapher", options); System.exit(0); } dataFile = commandLine.getOptionValue(serverURLOption.getOpt()); String[] otherArgs = commandLine.getArgs(); if (dataFile == null || otherArgs.length > 1) { System.out.println("Please specify a logfile"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Usage grapher", options); System.exit(0); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { } final UsagePlotter demo = new UsagePlotter("Usage", new File(dataFile)); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); }