List of usage examples for org.apache.commons.cli Options Options
Options
From source file:com.nexmo.client.examples.TestVoiceCall.java
public static void main(String[] argv) throws Exception { Options options = new Options().addOption("v", "Verbosity") .addOption("f", "from", true, "Phone number to call from") .addOption("t", "to", true, "Phone number to call") .addOption("h", "webhook", true, "URL to call for instructions"); CommandLineParser parser = new DefaultParser(); CommandLine cli;// w w w .j ava 2 s .c o m try { cli = parser.parse(options, argv); } catch (ParseException exc) { System.err.println("Parsing failed: " + exc.getMessage()); System.exit(128); return; } Queue<String> args = new LinkedList<String>(cli.getArgList()); String from = cli.getOptionValue("f"); String to = cli.getOptionValue("t"); System.out.println("From: " + from); System.out.println("To: " + to); NexmoClient client = new NexmoClient(new JWTAuthMethod("951614e0-eec4-4087-a6b1-3f4c2f169cb0", FileSystems.getDefault().getPath("valid_application_key.pem"))); client.getVoiceClient().createCall( new Call(to, from, "https://nexmo-community.github.io/ncco-examples/first_call_talk.json")); }
From source file:gr.demokritos.iit.demos.Demo.java
public static void main(String[] args) { try {/* w ww .j a va 2 s . c om*/ Options options = new Options(); options.addOption("h", HELP, false, "show help."); options.addOption("i", INPUT, true, "The file containing JSON " + " representations of tweets or SAG posts - 1 per line" + " default file looked for is " + DEFAULT_INFILE); options.addOption("o", OUTPUT, true, "Where to write the output " + " default file looked for is " + DEFAULT_OUTFILE); options.addOption("p", PROCESS, true, "Type of processing to do " + " ner for Named Entity Recognition re for Relation Extraction" + " default is NER"); options.addOption("s", SAG, false, "Whether to process as SAG posts" + " default is off - if passed means process as SAG posts"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); // DEFAULTS String filename = DEFAULT_INFILE; String outfilename = DEFAULT_OUTFILE; String process = NER; boolean isSAG = false; if (cmd.hasOption(HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("NER + RE extraction module", options); System.exit(0); } if (cmd.hasOption(INPUT)) { filename = cmd.getOptionValue(INPUT); } if (cmd.hasOption(OUTPUT)) { outfilename = cmd.getOptionValue(OUTPUT); } if (cmd.hasOption(SAG)) { isSAG = true; } if (cmd.hasOption(PROCESS)) { process = cmd.getOptionValue(PROCESS); } System.out.println(); System.out.println("Reading from file: " + filename); System.out.println("Process type: " + process); System.out.println("Processing SAG: " + isSAG); System.out.println("Writing to file: " + outfilename); System.out.println(); List<String> jsoni = new ArrayList(); Scanner in = new Scanner(new FileReader(filename)); while (in.hasNextLine()) { String json = in.nextLine(); jsoni.add(json); } PrintWriter writer = new PrintWriter(outfilename, "UTF-8"); System.out.println("Read " + jsoni.size() + " lines from " + filename); if (process.equalsIgnoreCase(RE)) { System.out.println("Running Relation Extraction"); System.out.println(); String json = API.RE(jsoni, isSAG); System.out.println(json); writer.print(json); } else { System.out.println("Running Named Entity Recognition"); System.out.println(); jsoni = API.NER(jsoni, isSAG); /* for(String json: jsoni){ NamedEntityList nel = NamedEntityList.fromJSON(json); nel.prettyPrint(); } */ for (String json : jsoni) { System.out.println(json); writer.print(json); } } writer.close(); } catch (ParseException | UnsupportedEncodingException | FileNotFoundException ex) { Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.omade.monitor.ClientApplication.java
public static void main(String[] args) throws Exception { logger.info("program start ..."); @SuppressWarnings("deprecation") CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "help", false, "Print this usage information"); options.addOption("c", "config", true, "configure the properties"); options.addOption("v", "version", false, "Print out Version information"); CommandLine commandLine = parser.parse(options, args); String configPath = "application.properties"; if (commandLine.hasOption('h')) { logger.info("Help Message"); System.exit(0);/*from w w w. j a v a 2 s . c om*/ } if (commandLine.hasOption('v')) { logger.info("Version Message"); } if (commandLine.hasOption('c')) { logger.info("Configuration Message"); configPath = commandLine.getOptionValue('c'); logger.info("configPath" + configPath); try { config = PropertiesUtil.getProperties(configPath); } catch (IllegalStateException e) { logger.error(e.getMessage()); System.exit(-1); } } executeFixedRate(); }
From source file:com.github.megatronking.svg.cli.Main.java
public static void main(String[] args) { Options opt = new Options(); opt.addOption("d", "dir", true, "the target svg directory"); opt.addOption("f", "file", true, "the target svg file"); opt.addOption("o", "output", true, "the output vector file or directory"); opt.addOption("w", "width", true, "the width size of target vector image"); opt.addOption("h", "height", true, "the height size of target vector image"); HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new PosixParser(); CommandLine cl;//from ww w. j a v a 2 s .c o m try { cl = parser.parse(opt, args); } catch (ParseException e) { formatter.printHelp(HELPER_INFO, opt); return; } if (cl == null) { formatter.printHelp(HELPER_INFO, opt); return; } int width = 0; int height = 0; if (cl.hasOption("w")) { width = SCU.parseInt(cl.getOptionValue("w")); } if (cl.hasOption("h")) { height = SCU.parseInt(cl.getOptionValue("h")); } String dir = null; String file = null; if (cl.hasOption("d")) { dir = cl.getOptionValue("d"); } else if (cl.hasOption("f")) { file = cl.getOptionValue("f"); } String output = null; if (cl.hasOption("o")) { output = cl.getOptionValue("o"); } if (output == null) { if (dir != null) { output = dir; } if (file != null) { output = FileUtils.noExtensionName(file) + ".xml"; } } if (dir == null && file == null) { formatter.printHelp(HELPER_INFO, opt); throw new RuntimeException("You must input the target svg file or directory"); } if (dir != null) { File inputDir = new File(dir); if (!inputDir.exists() || !inputDir.isDirectory()) { throw new RuntimeException("The path [" + dir + "] is not exist or valid directory"); } File outputDir = new File(output); if (outputDir.exists() || outputDir.mkdirs()) { svg2vectorForDirectory(inputDir, outputDir, width, height); } else { throw new RuntimeException("The path [" + outputDir + "] is not a valid directory"); } } if (file != null) { File inputFile = new File(file); if (!inputFile.exists() || !inputFile.isFile()) { throw new RuntimeException("The path [" + file + "] is not exist or valid file"); } svg2vectorForFile(inputFile, new File(output), width, height); } }
From source file:com.temenos.interaction.rimdsl.generator.launcher.Main.java
public static void main(String[] args) { // handle command line options final Options options = new Options(); OptionBuilder.withArgName("src"); OptionBuilder.withDescription("Model source"); OptionBuilder.hasArg();/*from w ww .ja v a2s.c om*/ OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optSrc = OptionBuilder.create("src"); OptionBuilder.withArgName("targetdir"); OptionBuilder.withDescription("Generator target directory"); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optTargetDir = OptionBuilder.create("targetdir"); options.addOption(optSrc); options.addOption(optTargetDir); // create the command line parser final CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (final ParseException exp) { System.err.println("Parsing arguments failed. Reason: " + exp); wrongCall(options); return; } // execute the generator Injector injector = new RIMDslStandaloneSetup().createInjectorAndDoEMFRegistration(); Generator generator = injector.getInstance(Generator.class); File srcFile = new File(line.getOptionValue(optSrc.getArgName())); if (srcFile.exists()) { boolean result = false; if (srcFile.isDirectory()) { result = generator.runGeneratorDir(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } else { result = generator.runGenerator(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } System.out.println("Code generation finished [" + result + "]"); } else { System.out.println("Src dir not found."); } }
From source file:cc.wikitools.lucene.FetchWikipediaArticle.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(//from w w w.j a va 2 s .c o m OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("article id").create(ID_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("article title").create(TITLE_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!(cmdline.hasOption(ID_OPTION) || cmdline.hasOption(TITLE_OPTION)) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(FetchWikipediaArticle.class.getName(), options); System.exit(-1); } File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION)); if (!indexLocation.exists()) { System.err.println("Error: " + indexLocation + " does not exist!"); System.exit(-1); } WikipediaSearcher searcher = new WikipediaSearcher(indexLocation); PrintStream out = new PrintStream(System.out, true, "UTF-8"); if (cmdline.hasOption(ID_OPTION)) { int id = Integer.parseInt(cmdline.getOptionValue(ID_OPTION)); Document doc = searcher.getArticle(id); if (doc == null) { System.err.print("id " + id + " doesn't exist!\n"); } else { out.println(doc.getField(IndexField.TEXT.name).stringValue()); } } else { String title = cmdline.getOptionValue(TITLE_OPTION); Document doc = searcher.getArticle(title); if (doc == null) { System.err.print("article \"" + title + "\" doesn't exist!\n"); } else { out.println(doc.getField(IndexField.TEXT.name).stringValue()); } } searcher.close(); out.close(); }
From source file:com.vaadin.buildhelpers.CompileTheme.java
/** * @param args//from w w w. j a v a2 s.c o m * @throws IOException * @throws ParseException */ public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); options.addOption("t", "theme", true, "the theme to compile"); options.addOption("v", "theme-version", true, "the version to add to the compiled theme"); options.addOption("f", "theme-folder", true, "the folder containing the theme"); CommandLineParser parser = new PosixParser(); CommandLine params = parser.parse(options, args); if (!params.hasOption("theme") || !params.hasOption("theme-folder")) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CompileTheme.class.getName(), options); return; } String themeName = params.getOptionValue("theme"); String themeFolder = params.getOptionValue("theme-folder"); String themeVersion = params.getOptionValue("theme-version"); // Regular theme try { processSassTheme(themeFolder, themeName, "styles", themeVersion); System.out.println("Compiling theme " + themeName + " styles successful"); } catch (Exception e) { System.err.println("Compiling theme " + themeName + " styles failed"); e.printStackTrace(); } // Legacy theme w/o .themename{} wrapping try { processSassTheme(themeFolder, themeName, "legacy-styles", themeVersion); System.out.println("Compiling theme " + themeName + " legacy-styles successful"); } catch (Exception e) { System.err.println("Compiling theme " + themeName + " legacy-styles failed"); e.printStackTrace(); } }
From source file:de.topobyte.osm4j.extra.executables.CreateIdBboxListGeometry.java
public static void main(String[] args) throws IOException { Options options = new Options(); // @formatter:off OptionHelper.addL(options, OPTION_INPUT, true, true, "an IdBboxList input file"); OptionHelper.addL(options, OPTION_OUTPUT, true, true, "a wkt file to create"); // @formatter:on CommandLine line = null;// w w w . j a v a2 s. 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); IdBboxListGeometryCreator task = new IdBboxListGeometryCreator(dirTree, fileOutput); task.execute(); }
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;/* w w w.j a v a 2 s . 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:Compiler.java
/** A command line entry point to the mini Java compiler. *///from w w w. ja v a 2 s . co m public static void main(String[] args) { CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("L", "LLVM", true, "LLVM Bitcode Output Location."); options.addOption("x", "x86", true, "x86 Output File Location"); options.addOption("l", "llvm", false, "Dump Human Readable LLVM Code."); options.addOption("i", "input", true, "Compile to x86 Assembly."); options.addOption("I", "interp", false, "Run the interpreter."); options.addOption("h", "help", false, "Print this help message."); options.addOption("V", "version", false, "Version information."); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("v")) { System.out.println("MiniJava Compiler"); System.out.println("Written By Mark Jones http://web.cecs.pdx.edu/~mpj/"); System.out.println("Extended for LLVM by Mitch Souders and Mark Smith"); } if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar mjc.jar -i <INPUT> (--x86 <OUT>|--LLVM <OUT>|--llvm)", options); System.exit(0); } int errors = 0; if (!cmd.hasOption("i")) { System.out.println("-i|--input requires a MiniJava input file"); System.out.println("--help for more info."); errors++; } if (!cmd.hasOption("x") && !cmd.hasOption("l") && !cmd.hasOption("L") && !cmd.hasOption("I")) { System.out.println("--x86|--llvm|--LLVM|--interp required for some sort of output."); System.out.println("--help for more info."); errors++; } if (errors > 0) { System.exit(1); } String inputFile = cmd.getOptionValue("i"); compile(inputFile, cmd); } catch (ParseException exp) { System.out.println("Argument Error: " + exp.getMessage()); } }