List of usage examples for org.apache.commons.cli OptionBuilder withArgName
public static OptionBuilder withArgName(String name)
From source file:io.s4.client.Adapter.java
@SuppressWarnings("static-access") public static void main(String args[]) throws IOException, InterruptedException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(/*w ww .j av a 2 s . c o m*/ OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); options.addOption(OptionBuilder.withArgName("userconfig").hasArg() .withDescription("user-defined legacy data adapter configuration file").create("d")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } String userConfigFilename = null; if (commandLine.hasOption("d")) { userConfigFilename = commandLine.getOptionValue("d"); } File userConfigFile = new File(userConfigFilename); if (!userConfigFile.isFile()) { System.err.println("Bad user configuration file: " + userConfigFilename); System.exit(1); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = configBase + File.separatorChar + "client-adapter-conf.xml"; File configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("adapter config file %s does not exist\n", configPath); System.exit(1); } // load adapter config xml ApplicationContext coreContext; coreContext = new FileSystemXmlApplicationContext("file:" + configPath); ApplicationContext context = coreContext; Adapter adapter = (Adapter) context.getBean("client_adapter"); ApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] { "file:" + userConfigFilename }, context); Map<?, ?> inputStubBeanMap = appContext.getBeansOfType(InputStub.class); Map<?, ?> outputStubBeanMap = appContext.getBeansOfType(OutputStub.class); if (inputStubBeanMap.size() == 0 && outputStubBeanMap.size() == 0) { System.err.println("No user-defined input/output stub beans"); System.exit(1); } ArrayList<InputStub> inputStubs = new ArrayList<InputStub>(inputStubBeanMap.size()); ArrayList<OutputStub> outputStubs = new ArrayList<OutputStub>(outputStubBeanMap.size()); // add all input stubs for (Map.Entry<?, ?> e : inputStubBeanMap.entrySet()) { String beanName = (String) e.getKey(); System.out.println("Adding InputStub " + beanName); inputStubs.add((InputStub) e.getValue()); } // add all output stubs for (Map.Entry<?, ?> e : outputStubBeanMap.entrySet()) { String beanName = (String) e.getKey(); System.out.println("Adding OutputStub " + beanName); outputStubs.add((OutputStub) e.getValue()); } adapter.setInputStubs(inputStubs); adapter.setOutputStubs(outputStubs); }
From source file:ch.psi.zmq.receiver.FileReceiver.java
public static void main(String[] args) { int port = 8888; String source = "localhost"; Options options = new Options(); options.addOption("h", false, "Help"); @SuppressWarnings("static-access") Option optionP = OptionBuilder.withArgName("port").hasArg() .withDescription("Source port (default: " + port + ")").create("p"); options.addOption(optionP);/*from w ww . jav a 2 s. com*/ @SuppressWarnings("static-access") Option optionS = OptionBuilder.withArgName("source").hasArg().isRequired().withDescription( "Source address of the ZMQ stream (default port " + port + " : use -p to set the port if needed)") .create("s"); options.addOption(optionS); @SuppressWarnings("static-access") Option optionD = OptionBuilder.withArgName("path").hasArg().isRequired() .withDescription("tpath for storing files with relative destination paths").create("d"); options.addOption(optionD); GnuParser parser = new GnuParser(); CommandLine line; String path = "."; try { line = parser.parse(options, args); if (line.hasOption(optionP.getOpt())) { port = Integer.parseInt(line.getOptionValue(optionP.getOpt())); } if (line.hasOption("h")) { HelpFormatter f = new HelpFormatter(); f.printHelp("receiver", options); return; } source = line.getOptionValue(optionS.getOpt()); path = line.getOptionValue(optionD.getOpt()); } catch (ParseException e) { System.err.println(e.getMessage()); HelpFormatter f = new HelpFormatter(); f.printHelp("receiver", options); System.exit(-1); } final FileReceiver r = new FileReceiver(source, port, path); r.receive(); // Control+C Signal.handle(new Signal("INT"), new SignalHandler() { int count = 0; public void handle(Signal sig) { if (count < 1) { count++; r.terminate(); } else { System.exit(-1); } } }); }
From source file:eu.fbk.dkm.sectionextractor.pantheon.WikipediaGoodTextExtractor.java
public static void main(String args[]) throws IOException { CommandLineWithLogger commandLineWithLogger = new CommandLineWithLogger(); commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("wikipedia xml dump file").isRequired().withLongOpt("wikipedia-dump").create("d")); commandLineWithLogger.addOption(OptionBuilder.withArgName("dir").hasArg() .withDescription("output directory in which to store output files").isRequired() .withLongOpt("output-dir").create("o")); commandLineWithLogger/* ww w.ja v a2 s.com*/ .addOption(OptionBuilder.withDescription("use NAF format").withLongOpt("naf").create("n")); commandLineWithLogger.addOption(OptionBuilder.withDescription("tokenize and ssplit with Stanford") .withLongOpt("stanford").create("s")); commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("Filter file") .withLongOpt("filter").create("f")); commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("ID and category file").withLongOpt("idcat").create("i")); commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("Redirect file") .withLongOpt("redirect").create("r")); commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg() .withDescription( "number of threads (default " + AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER + ")") .withLongOpt("num-threads").create("t")); commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg() .withDescription("number of pages to process (default all)").withLongOpt("num-pages").create("p")); commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg() .withDescription("receive notification every n pages (default " + AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT + ")") .withLongOpt("notification-point").create("b")); commandLineWithLogger.addOption(new Option("n", "NAF format")); CommandLine commandLine = null; try { commandLine = commandLineWithLogger.getCommandLine(args); PropertyConfigurator.configure(commandLineWithLogger.getLoggerProps()); } catch (Exception e) { System.exit(1); } int numThreads = Integer.parseInt(commandLine.getOptionValue("num-threads", Integer.toString(AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER))); int numPages = Integer.parseInt(commandLine.getOptionValue("num-pages", Integer.toString(AbstractWikipediaExtractor.DEFAULT_NUM_PAGES))); int notificationPoint = Integer.parseInt(commandLine.getOptionValue("notification-point", Integer.toString(AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT))); boolean nafFormat = commandLine.hasOption("n"); boolean useStanford = commandLine.hasOption("s"); HashMap<Integer, String> idCategory = new HashMap<>(); String idcatFileName = commandLine.getOptionValue("idcat"); if (idcatFileName != null) { logger.info("Loading categories"); File idcatFile = new File(idcatFileName); if (idcatFile.exists()) { List<String> lines = Files.readLines(idcatFile, Charsets.UTF_8); for (String line : lines) { line = line.trim(); if (line.length() == 0) { continue; } String[] parts = line.split("\\s+"); if (parts.length < 3) { continue; } idCategory.put(Integer.parseInt(parts[1]), parts[2]); } } } HashMap<String, String> redirects = new HashMap<>(); String redirectFileName = commandLine.getOptionValue("redirect"); if (redirectFileName != null) { logger.info("Loading redirects"); File redirectFile = new File(redirectFileName); if (redirectFile.exists()) { List<String> lines = Files.readLines(redirectFile, Charsets.UTF_8); for (String line : lines) { line = line.trim(); if (line.length() == 0) { continue; } String[] parts = line.split("\\t+"); if (parts.length < 2) { continue; } redirects.put(parts[0], parts[1]); } } } HashSet<String> pagesToConsider = null; String filterFileName = commandLine.getOptionValue("filter"); if (filterFileName != null) { logger.info("Loading file list"); File filterFile = new File(filterFileName); if (filterFile.exists()) { pagesToConsider = new HashSet<>(); List<String> lines = Files.readLines(filterFile, Charsets.UTF_8); for (String line : lines) { line = line.trim(); if (line.length() == 0) { continue; } line = line.replaceAll("\\s+", "_"); pagesToConsider.add(line); addRedirects(pagesToConsider, redirects, line, 0); } } } ExtractorParameters extractorParameters = new ExtractorParameters( commandLine.getOptionValue("wikipedia-dump"), commandLine.getOptionValue("output-dir")); File outputFolder = new File(commandLine.getOptionValue("output-dir")); if (!outputFolder.exists()) { boolean mkdirs = outputFolder.mkdirs(); if (!mkdirs) { throw new IOException("Unable to create folder " + outputFolder.getAbsolutePath()); } } WikipediaExtractor wikipediaPageParser = new WikipediaGoodTextExtractor(numThreads, numPages, extractorParameters.getLocale(), outputFolder, nafFormat, pagesToConsider, useStanford, idCategory); wikipediaPageParser.setNotificationPoint(notificationPoint); wikipediaPageParser.start(extractorParameters); logger.info("extraction ended " + new Date()); }
From source file:com.wdt.java.OptionControlClass.java
public static Options OptionControlClass() { Option conffile = OptionBuilder.withArgName("conffile").hasArg() .withDescription("use given file for DataSource configuration.").create("conffile"); Option url = OptionBuilder.withArgName("url").hasArg() .withDescription("use given url to configure DataSourcce.").create("url"); Option passwd = OptionBuilder.withArgName("passwd").hasArg() .withDescription("use given password to configure DataDource.").create("passwd"); Option user = OptionBuilder.withArgName("user").hasArg() .withDescription("use given user to configure DataSource.").create("user"); Option propertieFile = OptionBuilder.withArgName("propertieFile").hasArg() .withDescription("use given file to get/write properties.").create("propertieFile"); Option propTableOwner = OptionBuilder.withArgName("propTableOwner").hasArg() .withDescription("owner of table containing properties.").create("propTableOwner"); Option propTableName = OptionBuilder.withArgName("propTableName").hasArg() .withDescription("Name of table containing properties.").create("propTableName"); Options options = new Options(); options.addOption("db2file", false, "direction of properties flow"); options.addOption("file2db", false, "direction of properties flow"); options.addOption("?", false, "display this help"); options.addOption(conffile);/* w w w. ja v a 2s . co m*/ options.addOption(url); options.addOption(passwd); options.addOption(user); options.addOption(propertieFile); options.addOption(propTableOwner); options.addOption(propTableName); return options; }
From source file:ivory.core.tokenize.Tokenizer.java
@SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("full path to model file or directory").hasArg() .withDescription("model file").create("model")); options.addOption(OptionBuilder.withArgName("full path to input file").hasArg() .withDescription("input file").isRequired().create("input")); options.addOption(OptionBuilder.withArgName("full path to output file").hasArg() .withDescription("output file").isRequired().create("output")); options.addOption(OptionBuilder.withArgName("en | zh | de | fr | ar | tr | es").hasArg() .withDescription("2-character language code").isRequired().create("lang")); options.addOption(OptionBuilder.withArgName("path to stopwords list").hasArg() .withDescription("one stopword per line").create("stopword")); options.addOption(OptionBuilder.withArgName("path to stemmed stopwords list").hasArg() .withDescription("one stemmed stopword per line").create("stemmed_stopword")); options.addOption(OptionBuilder.withArgName("true|false").hasArg().withDescription("turn on/off stemming") .create("stem")); options.addOption(OptionBuilder.withDescription("Hadoop option to load external jars") .withArgName("jar packages").hasArg().create("libjars")); CommandLine cmdline;/*from w w w . ja va2 s . c o m*/ CommandLineParser parser = new GnuParser(); try { String stopwordList = null, stemmedStopwordList = null, modelFile = null; boolean isStem = true; cmdline = parser.parse(options, args); if (cmdline.hasOption("stopword")) { stopwordList = cmdline.getOptionValue("stopword"); } if (cmdline.hasOption("stemmed_stopword")) { stemmedStopwordList = cmdline.getOptionValue("stemmed_stopword"); } if (cmdline.hasOption("stem")) { isStem = Boolean.parseBoolean(cmdline.getOptionValue("stem")); } if (cmdline.hasOption("model")) { modelFile = cmdline.getOptionValue("model"); } ivory.core.tokenize.Tokenizer tokenizer = TokenizerFactory.createTokenizer( cmdline.getOptionValue("lang"), modelFile, isStem, stopwordList, stemmedStopwordList, null); BufferedWriter out = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(cmdline.getOptionValue("output")), "UTF8")); BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(cmdline.getOptionValue("input")), "UTF8")); String line = null; while ((line = in.readLine()) != null) { String[] tokens = tokenizer.processContent(line); String s = ""; for (String token : tokens) { s += token + " "; } out.write(s.trim() + "\n"); } in.close(); out.close(); } catch (Exception exp) { System.out.println(exp); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Tokenizer", options); System.exit(-1); } }
From source file:com.comcast.oscar.cli.commands.Key.java
/** * Set option parameters for command Key * @return Option/*from w ww . jav a2 s . c o m*/ */ public static Option OptionParameters() { OptionBuilder.withArgName("key filename"); OptionBuilder.hasArgs(1); OptionBuilder.hasOptionalArgs(); OptionBuilder.withValueSeparator(' '); OptionBuilder.withLongOpt("key"); OptionBuilder.withDescription("Use this sharedsecret to compile the file - DOCSIS ONLY."); return OptionBuilder.create("k"); }
From source file:com.comcast.oscar.cli.commands.TLV.java
/** * Set option parameters for command TLV * @return Option/*from w ww . j av a 2s .c o m*/ */ public static final Option OptionParameters() { OptionBuilder.withArgName("TLV"); OptionBuilder.hasArgs(1); OptionBuilder.hasOptionalArgs(); OptionBuilder.withValueSeparator(' '); OptionBuilder.withLongOpt("tlv"); OptionBuilder.withDescription("Insert this TLV during file compilation."); return OptionBuilder.create("t"); }
From source file:com.comcast.oscar.cli.commands.Firmware.java
/** * Set option parameters for command Firmware * @return Option/*from www . j a v a2 s . c o m*/ */ public static final Option OptionParameters() { OptionBuilder.withArgName("filename"); OptionBuilder.hasArgs(1); OptionBuilder.hasOptionalArgs(); OptionBuilder.withValueSeparator(' '); OptionBuilder.withLongOpt("firmware"); OptionBuilder.withDescription("Insert this firmware during file compilation."); return OptionBuilder.create("f"); }
From source file:com.comcast.oscar.cli.commands.MaxCPE.java
/** * Set option parameters for command Maximum CPE * @return Option// w ww .jav a 2 s. co m */ public static final Option OptionParameters() { OptionBuilder.withArgName("maximum CPEs"); OptionBuilder.hasArgs(1); OptionBuilder.hasOptionalArgs(); OptionBuilder.withValueSeparator(' '); OptionBuilder.withLongOpt("maxCPE"); OptionBuilder.withDescription("Insert the maximum CPEs during file compilation EX: 5."); return OptionBuilder.create("m"); }
From source file:list.Main.java
private static Options getOptions() { Option dir = OptionBuilder.withArgName("dir").hasArg().withDescription("list files in given dir") .create("dir"); Options options = new Options(); options.addOption(dir);/*from w w w .j ava 2 s . com*/ return options; }