List of usage examples for org.apache.commons.cli DefaultParser DefaultParser
DefaultParser
From source file:de.topobyte.osm4j.extra.executables.CreateDataTreeBoxGeometry.java
public static void main(String[] args) throws IOException { Options options = new Options(); // @formatter:off OptionHelper.addL(options, OPTION_INPUT, true, true, "directory with data tree"); OptionHelper.addL(options, OPTION_OUTPUT, true, true, "a wkt file to create"); // @formatter:on CommandLine line = null;//from w w w .ja va 2s . c om try { line = new DefaultParser().parse(options, args); } catch (ParseException e) { System.out.println("unable to parse command line: " + e.getMessage()); new HelpFormatter().printHelp(HELP_MESSAGE, options); System.exit(1); } String pathInput = line.getOptionValue(OPTION_INPUT); String pathOutput = line.getOptionValue(OPTION_OUTPUT); File dirTree = new File(pathInput); File fileOutput = new File(pathOutput); DataTreeBoxGeometryCreator task = new DataTreeBoxGeometryCreator(dirTree, fileOutput); task.execute(); }
From source file:com.google.api.codegen.configgen.ConfigGeneratorTool.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("descriptor_set") .desc("The descriptor set representing the compiled input protos.").hasArg() .argName("DESCRIPTOR-SET").required(true).build()); options.addOption(//w w w. j ava 2 s. co m Option.builder().longOpt("service_yaml").desc("The service YAML configuration file or files.") .hasArg().argName("SERVICE-YAML").required(true).build()); options.addOption( Option.builder("o").longOpt("output").desc("The directory in which to output the generated config.") .hasArg().argName("OUTPUT-FILE").required(true).build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("ConfigGeneratorTool", options); } generate(cl.getOptionValue("descriptor_set"), cl.getOptionValues("service_yaml"), cl.getOptionValue("output")); }
From source file:com.google.endpoints.examples.bookstore.BookstoreClient.java
public static void main(String[] args) throws Exception { Options options = createOptions();//from ww w . ja va2s . c o m CommandLineParser parser = new DefaultParser(); CommandLine params; try { params = parser.parse(options, args); } catch (ParseException e) { System.err.println("Invalid command line: " + e.getMessage()); printUsage(options); return; } String address = params.getOptionValue("bookstore", DEFAULT_ADDRESS); String apiKey = params.getOptionValue("api_key"); String authToken = params.getOptionValue("auth_token"); String operation = params.getOptionValue("operation", "list"); // Create gRPC stub. BookstoreGrpc.BookstoreBlockingStub bookstore = createBookstoreStub(address, apiKey, authToken); if ("list".equals(operation)) { listShelves(bookstore); } else if ("create".equals(operation)) { createShelf(bookstore); } else if ("enumerate".equals(operation)) { enumerate(bookstore); } }
From source file:PlyBounder.java
public static void main(String[] args) { // Get the commandline arguments Options options = new Options(); // Available options Option plyPath = OptionBuilder.withArgName("dir").hasArg() .withDescription("directory containing input .ply files").create("plyPath"); Option boundingbox = OptionBuilder.withArgName("string").hasArg() .withDescription("bounding box in WKT notation").create("boundingbox"); Option outputPlyFile = OptionBuilder.withArgName("file").hasArg().withDescription("output PLY file name") .create("outputPlyFile"); options.addOption(plyPath);//from ww w .j av a2 s.c o m options.addOption(boundingbox); options.addOption(outputPlyFile); String plydir = "."; String boundingboxstr = ""; String outputfilename = ""; CommandLineParser parser = new DefaultParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); boundingboxstr = line.getOptionValue("boundingbox"); outputfilename = line.getOptionValue("outputPlyFile"); if (line.hasOption("plyPath")) { // print the value of block-size plydir = line.getOptionValue("plyPath"); System.out.println("Using plyPath=" + plydir); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PlyBounder", options); } //System.out.println( "plyPath=" + line.getOptionValue( "plyPath" ) ); } catch (ParseException exp) { System.err.println("Error getting arguments: " + exp.getMessage()); } // input directory // Get list of files File dir = new File(plydir); //System.out.println("Getting all files in " + dir.getCanonicalPath()); List<File> files = (List<File>) FileUtils.listFiles(dir, new String[] { "ply", "PLY" }, false); for (File file : files) { try { System.out.println("file=" + file.getCanonicalPath()); } catch (IOException e) { e.printStackTrace(); } } String sometempfile = "magweg.wkt"; String s = null; // Loop through .ply files in directory for (File file : files) { try { String cmdl[] = { "./ply-tool.py", "intersection", file.getCanonicalPath(), boundingboxstr, sometempfile }; //System.out.println("Running: " + Arrays.toString(cmdl)); Process p = Runtime.getRuntime().exec(cmdl); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("cmdout:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("cmderr:\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (IOException e) { e.printStackTrace(); } } // Write new .ply file //ply-tool write setfile outputPlyFile try { String cmdl = "./ply-tool.py write " + sometempfile + " " + outputfilename; System.out.println("Running: " + cmdl); Process p = Runtime.getRuntime().exec(cmdl); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("cmdout:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("cmderr:\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (IOException e) { e.printStackTrace(); } // Done System.out.println("Done"); }
From source file:com.google.cloud.logging.v2.LoggingSmokeTest.java
public static void main(String args[]) { Logger.getLogger("").setLevel(Level.WARNING); try {//from w ww. j a v a 2 s . 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:de.topobyte.osm4j.extra.executables.CreateEmptyDataTreeFromOther.java
public static void main(String[] args) throws IOException { Options options = new Options(); // @formatter:off OptionHelper.addL(options, OPTION_INPUT, true, true, "directory with data tree"); OptionHelper.addL(options, OPTION_OUTPUT, true, true, "directory in which to create a new data tree"); // @formatter:on CommandLine line = null;//from w ww. j a v a 2 s . co m try { line = new DefaultParser().parse(options, args); } catch (ParseException e) { System.out.println("unable to parse command line: " + e.getMessage()); new HelpFormatter().printHelp(HELP_MESSAGE, options); System.exit(1); } String pathInput = line.getOptionValue(OPTION_INPUT); String pathOutput = line.getOptionValue(OPTION_OUTPUT); File dirInputTree = new File(pathInput); File dirOutputTree = new File(pathOutput); EmptyDataTreeFromOtherCreator task = new EmptyDataTreeFromOtherCreator(dirInputTree, dirOutputTree); task.execute(); }
From source file:com.uber.tchannel.ping.PingServer.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("p", "port", true, "Server Port to connect to"); 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;// w ww .j a va 2s .c o m } int port = Integer.parseInt(cmd.getOptionValue("p", "8888")); System.out.println(String.format("Starting server on port: %d", port)); new PingServer(port).run(); System.out.println("Stopping server..."); }
From source file:ie.peternagy.jcrypto.cli.JCryptoCli.java
public static void main(String[] args) { long startTime = System.currentTimeMillis(); try {//from w w w . j ava 2 s .co m CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(OPTIONS, args); isVerbose = line.hasOption('v'); routeParams(line); if (isVerbose) { System.out.printf("\n Process finished in %dms\n\n", System.currentTimeMillis() - startTime); } } catch (org.apache.commons.cli.ParseException ex) { printCliHelp(); //@todo: override the logger if not in debug mode Logger.getLogger(JCryptoCli.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.yahoo.gondola.cli.GondolaAgent.java
public static void main(String[] args) throws ParseException, IOException { PropertyConfigurator.configure("conf/log4j.properties"); CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption("port", true, "Listening port"); options.addOption("config", true, "config file"); options.addOption("h", false, "help"); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("help")) { new HelpFormatter().printHelp("GondolaAgent", options); return;//from www.java 2 s . c om } if (commandLine.hasOption("port")) { port = Integer.parseInt(commandLine.getOptionValue("port")); } else { port = 1200; } if (commandLine.hasOption("config")) { configFile = commandLine.getOptionValue("config"); } config = new Config(new File(configFile)); logger.info("Initialize system, kill all gondola processes"); new DefaultExecutor().execute(org.apache.commons.exec.CommandLine.parse("bin/gondola-local-test.sh stop")); new GondolaAgent(port); }
From source file:de.ncoder.studipsync.Starter.java
public static void main(String[] args) throws Exception { boolean displayHelp = false; CommandLineParser parser = new DefaultParser(); try {//from w ww. j av a2 s . c om CommandLine cmd = parser.parse(OPTIONS, args); if (cmd.hasOption(OPTION_HELP)) { displayHelp = true; return; } Syncer syncer = createSyncer(cmd); StorageLog storeLog = new StorageLog(); syncer.getStorage().registerListener(storeLog); try { log.info("Started " + getImplementationTitle() + " " + getImplementationVersion()); syncer.sync(); log.info(storeLog.getStatusMessage(syncer.getStorage().getRoot())); log.info("Finished"); } finally { syncer.close(); } } catch (ParseException e) { System.out.println("Illegal arguments passed. " + e.getMessage()); displayHelp = true; } finally { if (displayHelp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("studip-sync", OPTIONS); } } //TODO AWT Event Queue blocks termination with modality level 1 System.exit(0); }