List of usage examples for org.apache.commons.cli Options Options
Options
From source file:it.iit.genomics.cru.genomics.misc.apps.Vcf2tabApp.java
public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); Option helpOpt = new Option("help", "print this message."); options.addOption(helpOpt);// ww w. ja v a 2 s .co m Option option1 = new Option("f", "filename", true, "VCF file to load"); option1.setRequired(true); options.addOption(option1); option1 = new Option("o", "outputfile", true, "outputfilene"); option1.setRequired(true); options.addOption(option1); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { // parse the command line arguments cmd = parser.parse(options, args, true); } catch (ParseException exp) { displayUsage("vcf2tab", options); System.exit(1); } if (cmd.hasOption("help")) { displayUsage("vcf2tab", options); System.exit(0); } String filename = cmd.getOptionValue("f"); String outputfilename = cmd.getOptionValue("o"); Vcf2tab loader = new Vcf2tab(); loader.file2tab(filename, outputfilename); //(args[0]); }
From source file:com.dasasian.chok.tool.ZkTool.java
public static void main(String[] args) { final Options options = new Options(); Option lsOption = new Option("ls", true, "list zp path contents"); lsOption.setArgName("path"); Option readOption = new Option("read", true, "read and print zp path contents"); readOption.setArgName("path"); Option rmOption = new Option("rm", true, "remove zk files"); rmOption.setArgName("path"); Option rmrOption = new Option("rmr", true, "remove zk directories"); rmrOption.setArgName("path"); OptionGroup actionGroup = new OptionGroup(); actionGroup.setRequired(true);//from w w w . java 2 s. c o m actionGroup.addOption(lsOption); actionGroup.addOption(readOption); actionGroup.addOption(rmOption); actionGroup.addOption(rmrOption); options.addOptionGroup(actionGroup); final CommandLineParser parser = new GnuParser(); HelpFormatter formatter = new HelpFormatter(); try { final CommandLine line = parser.parse(options, args); ZkTool zkTool = new ZkTool(); if (line.hasOption(lsOption.getOpt())) { String path = line.getOptionValue(lsOption.getOpt()); zkTool.ls(path); } else if (line.hasOption(readOption.getOpt())) { String path = line.getOptionValue(readOption.getOpt()); zkTool.read(path); } else if (line.hasOption(rmOption.getOpt())) { String path = line.getOptionValue(rmOption.getOpt()); zkTool.rm(path, false); } else if (line.hasOption(rmrOption.getOpt())) { String path = line.getOptionValue(rmrOption.getOpt()); zkTool.rm(path, true); } zkTool.close(); } catch (ParseException e) { System.out.println(e.getClass().getSimpleName() + ": " + e.getMessage()); formatter.printHelp(ZkTool.class.getSimpleName(), options); } }
From source file:com.rapleaf.hank.cli.AddRingGroup.java
public static void main(String[] args) throws IOException, ParseException, InvalidConfigurationException { Options options = new Options(); options.addOption("r", "ring-group", true, "the name of the ring group to be created"); options.addOption("d", "domain-group", true, "the name of the domain group that this ring group will be linked to"); options.addOption("c", "config", true, "path of a valid config file with coordinator connection information"); try {//ww w.j a v a 2 s. c om CommandLine line = new GnuParser().parse(options, args); CommandLineChecker.check(line, options, new String[] { "config", "ring-group", "domain-group" }, AddRingGroup.class); ClientConfigurator configurator = new YamlClientConfigurator(line.getOptionValue("config")); addRingGroup(configurator, line.getOptionValue("ring-group"), line.getOptionValue("domain-group")); } catch (ParseException e) { new HelpFormatter().printHelp("add_domain", options); throw e; } }
From source file:net.anthonypoon.ngram.removespecial.Main.java
public static void main(String args[]) throws Exception { Options options = new Options(); options.addOption("a", "action", true, "Action"); options.addOption("i", "input", true, "input"); options.addOption("o", "output", true, "output"); options.addOption("c", "compressed", false, "is lzo zipped"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); Configuration conf = new Configuration(); Job job = Job.getInstance(conf);/*from w w w . j a v a2s. c om*/ if (cmd.hasOption("compressed")) { job.setInputFormatClass(SequenceFileAsTextInputFormat.class); } job.setJarByClass(Main.class); //job.setInputFormatClass(SequenceFileAsTextInputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); switch (cmd.getOptionValue("action")) { case "list": job.setMapperClass(ListMapper.class); //job.setNumReduceTasks(0); job.setReducerClass(ListReducer.class); break; case "remove": job.setMapperClass(RemoveMapper.class); job.setReducerClass(RemoveReducer.class); break; default: throw new IllegalArgumentException("Missing action"); } String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()); FileInputFormat.setInputPaths(job, new Path(cmd.getOptionValue("input"))); FileOutputFormat.setOutputPath(job, new Path(cmd.getOptionValue("output") + "/" + timestamp)); System.exit(job.waitForCompletion(true) ? 0 : 1); }
From source file:edu.ucsb.cs.eager.sa.cerebro.ProfessorX.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", "input-file", true, "Path to input xml file"); options.addOption("r", "root-path", true, "Root path of all Git repositories"); CommandLine cmd;//w w w . j a v a 2 s.co m try { CommandLineParser parser = new BasicParser(); cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage() + "\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Cerebro", options); return; } String inputFileName = cmd.getOptionValue("i"); if (inputFileName == null) { System.err.println("input file path is required"); return; } String rootPath = cmd.getOptionValue("r"); if (rootPath == null) { System.err.println("root path is required"); return; } File inputFile = new File(inputFileName); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); Document doc; try { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); doc = dBuilder.parse(inputFile); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); return; } NodeList repoList = doc.getElementsByTagName("repo"); for (int i = 0; i < repoList.getLength(); i++) { Element repo = (Element) repoList.item(i); String name = repo.getElementsByTagName("name").item(0).getTextContent(); String classPath = repo.getElementsByTagName("classpath").item(0).getTextContent(); Set<String> classes = new LinkedHashSet<String>(); NodeList classesList = repo.getElementsByTagName("classes").item(0).getChildNodes(); for (int j = 0; j < classesList.getLength(); j++) { if (!(classesList.item(j) instanceof Element)) { continue; } classes.add(classesList.item(j).getTextContent()); } analyzeRepo(rootPath, name, classPath, classes); } }
From source file:cc.wikitools.lucene.FindWikipediaArticleId.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(//from w ww.j a va2s.co m OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_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(TITLE_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(FindWikipediaArticleId.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); } String title = cmdline.getOptionValue(TITLE_OPTION); PrintStream out = new PrintStream(System.out, true, "UTF-8"); WikipediaSearcher searcher = new WikipediaSearcher(indexLocation); int id = searcher.getArticleId(title); out.println(title + ": id = " + id); searcher.close(); out.close(); }
From source file:com.google.cloud.pubsub.v1.TopicAdminSmokeTest.java
public static void main(String args[]) { Logger.getLogger("").setLevel(Level.WARNING); try {/*from w w w .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("TopicAdminSmokeTest", 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:it.anyplace.sync.webclient.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("C", "set-config", true, "set config file for s-client"); options.addOption("h", "help", false, "print help"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("s-client", options); return;//from www. ja va 2 s. com } File configFile = cmd.hasOption("C") ? new File(cmd.getOptionValue("C")) : new File(System.getProperty("user.home"), ".s-client.properties"); logger.info("using config file = {}", configFile); try (ConfigurationService configuration = ConfigurationService.newLoader().loadFrom(configFile)) { FileUtils.cleanDirectory(configuration.getTemp()); KeystoreHandler.newLoader().loadAndStore(configuration); logger.debug("{}", configuration.getStorageInfo().dumpAvailableSpace()); try (HttpService httpService = new HttpService(configuration)) { httpService.start(); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse( URI.create("http://localhost:" + httpService.getPort() + "/web/webclient.html")); } httpService.join(); } } }
From source file:example.ConfigurationsExample.java
public static void main(String[] args) { String jdbcPropToLoad = "prod.properties"; CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("d", "dev", false, "Dev tag to launch app in dev mode. Means that app will launch embedded mckoi db."); try {/* w w w . j ava2 s .c om*/ CommandLine line = parser.parse(options, args); if (line.hasOption("d")) { System.err.println("App is in DEV mode"); jdbcPropToLoad = "dev.properties"; } } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); } Properties p = new Properties(); try { p.load(ConfigurationsExample.class.getResourceAsStream("/" + jdbcPropToLoad)); } catch (IOException e) { System.err.println("Properties loading failed. Reason: " + e.getMessage()); } try { String clazz = p.getProperty("driver.class"); Class.forName(clazz); System.out.println(" Jdbc driver loaded :" + clazz); } catch (ClassNotFoundException e) { System.err.println("Jdbc Driver class loading failed. Reason: " + e.getMessage()); e.printStackTrace(); } }
From source file:edu.mit.csail.sdg.alloy4.VizGUI.java
/** * @param args/*ww w.j a v a2s.c o m*/ */ public static void main(String[] args) { // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options optionsArg = new Options(); Option helpOpt = new Option("?", "help", false, "print this message"); Option inputFileOpt = new Option("f", "file", true, "the name of the xml file to show"); inputFileOpt.setRequired(true); optionsArg.addOption(helpOpt); optionsArg.addOption(inputFileOpt); CommandLine line = null; try { // parse the command line arguments line = parser.parse(optionsArg, args); if (line.hasOption(helpOpt.getOpt())) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("vizgui", optionsArg); return; } } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("vizgui", optionsArg); return; } String inputFile = null; if (line.hasOption(inputFileOpt.getOpt())) { inputFile = line.getOptionValue(inputFileOpt.getOpt()); if (inputFile == null) { System.err.println("Invalid input file"); } } new edu.mit.csail.sdg.alloy4viz.VizGUI(true, inputFile, null); }