List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:com.rackspacecloud.client.cloudfiles.sample.FilesMakeContainer.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);//from w ww .j ava 2 s .com CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); String containerName = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); createContaier(containerName); } //end if (line.hasOption("container")) else if (args.length > 0) { //If we got this far there are command line arguments but none of what we expected treat the first one as the Container name containerName = args[0]; createContaier(containerName); } else { System.err.println("You must provide the -container with a valid value for this to work !"); System.exit(-1); } } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (Exception err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:de.drippinger.cytricHelper.CommandLineStart.java
public static void main(String[] args) throws ParseException { CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(createOptions(), args); CytricHelper helper = new CytricHelper(); if (cmd.hasOption("f") && cmd.hasOption("e")) { try {//from w ww. j a va2 s .co m helper.manipulatePdf(cmd.getOptionValue("f"), cmd.getOptionValue("e")); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } else { printHelp(); } }
From source file:edu.washington.data.sentimentreebank.StanfordNLPDict.java
public static void main(String args[]) { Options options = new Options(); options.addOption("d", "dict", true, "dictionary file."); options.addOption("s", "sentiment", true, "sentiment value file."); CommandLineParser parser = new GnuParser(); try {//from ww w . j a va2 s .c o m CommandLine line = parser.parse(options, args); if (!line.hasOption("dict") && !line.hasOption("sentiment")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("StanfordNLPDict", options); return; } Path dictPath = Paths.get(line.getOptionValue("dict")); Path sentimentPath = Paths.get(line.getOptionValue("sentiment")); StanfordNLPDict snlp = new StanfordNLPDict(dictPath, sentimentPath); String sentence = "take off"; System.out.printf("sentence [%1$s] %2$s\n", sentence, String.valueOf(snlp.getPhraseSentiment(sentence))); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("StanfordNLPDict", options); } catch (IOException ex) { Logger.getLogger(StanfordNLPDict.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.slothpetrochemical.bridgeprob.BridgeProblemApp.java
public static void main(final String[] args) throws ParseException { Options commandLineOptions = createOptions(); PosixParser clParser = new PosixParser(); CommandLine cl = clParser.parse(commandLineOptions, args); if (cl.getArgs().length == 0 || cl.hasOption("h")) { new HelpFormatter().printHelp("crossing_times...", commandLineOptions); } else {//from w w w .j a va 2 s . c o m String[] clArgs = cl.getArgs(); Integer[] times = new Integer[clArgs.length]; for (int i = 0; i < clArgs.length; ++i) { Integer intTime = Integer.parseInt(clArgs[i]); times[i] = intTime; } Arrays.sort(times); BridgeProblemApp app = new BridgeProblemApp(Arrays.asList(times)); app.run(); } }
From source file:com.commonsware.android.gcm.cmd.GCM.java
@SuppressWarnings("static-access") public static void main(String[] args) { Option helpOpt = new Option("h", "help", false, "print this message"); Option apiKeyOpt = OptionBuilder.withArgName("key").hasArg().isRequired().withDescription("GCM API key") .withLongOpt("apiKey").create('a'); Option deviceOpt = OptionBuilder.withArgName("regId").hasArg().isRequired() .withDescription("device to send to").withLongOpt("device").create('d'); Option dataOpt = OptionBuilder.withArgName("key=value").hasArgs(2).withDescription("datum to send") .withValueSeparator().withLongOpt("data").create('D'); Options options = new Options(); options.addOption(apiKeyOpt);// www. j ava 2 s .co m options.addOption(deviceOpt); options.addOption(dataOpt); options.addOption(helpOpt); CommandLineParser parser = new PosixParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption('h') || !line.hasOption('a') || !line.hasOption('d')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("gcm", options, true); } else { sendMessage(line.getOptionValue('a'), Arrays.asList(line.getOptionValues('d')), line.getOptionProperties("data")); } } catch (org.apache.commons.cli.MissingOptionException moe) { System.err.println("Invalid command syntax"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("gcm", options, true); } catch (Exception e) { e.printStackTrace(); } }
From source file:is.iclt.icenlp.runner.RunLemmald.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); try {/*from www .j a va2 s. com*/ // parse the command line arguments CommandLine cmdLine = parser.parse(options, args); if (cmdLine.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("lemmatize.sh", options); } else { runConsole(cmdLine); } } catch (ParseException exp) { // oops, something went wrong System.err.println("Could not parse command line arguments. Reason: " + exp.getMessage()); } }
From source file:com.falcon.orca.Main.java
public static void main(String[] args) throws IOException { Option mode = Option.builder("mo").longOpt("mode").required(true).hasArg(true) .desc("Mode to start the node " + "in, possible values are standalone master slave").build(); Option host = Option.builder("ho").longOpt("host").hasArg(true).desc("Machine name").build(); Options modeOptions = new Options(); modeOptions.addOption(mode);//from w w w .j av a 2 s . c om modeOptions.addOption(host); CommandLineParser commandLineParser = new DefaultParser(); ModeHandler handler; final ActorSystem actorSystem = ActorSystem.create(); String machineName = "127.0.0.1"; try { CommandLine commandLine = commandLineParser.parse(modeOptions, args); if (commandLine.hasOption("host")) { machineName = commandLine.getOptionValue("host"); } if (commandLine.hasOption("mode")) { String modeValue = commandLine.getOptionValue("mode"); if ("standalone".equalsIgnoreCase(modeValue)) { handler = new StandAloneHandler(actorSystem); handler.handle(); } else if ("master".equalsIgnoreCase(modeValue)) { handler = new MasterHandler(actorSystem, 1, machineName); handler.handle(); } else if ("slave".equalsIgnoreCase(modeValue)) { handler = new SlaveHandler(actorSystem); handler.handle(); } else { actorSystem.shutdown(); System.out .println("Mode is required, use -mo or --mode, possible values are standalone, master " + "and slave"); } } else { actorSystem.shutdown(); System.out .println("Mode is required, use -mo or --mode, possible values are standalone, master and " + "slave"); } } catch (ParseException e) { actorSystem.shutdown(); System.out.println( "Mode is required, use -mo or --mode, possible values are standalone, master and slave"); } }
From source file:io.github.azige.mages.Cli.java
public static void main(String[] args) { Options options = new Options().addOption("h", "help", false, "print this message") .addOption(Option.builder("r").hasArg().argName("bundle").desc("set the ResourceBundle").build()) .addOption(Option.builder("l").hasArg().argName("locale").desc("set the locale").build()) .addOption(Option.builder("t").hasArg().argName("template").desc("set the template").build()) .addOption(Option.builder("p").hasArg().argName("plugin dir") .desc("set the directory to load plugins").build()) .addOption(Option.builder("f").desc("force override existed file").build()); try {/*from w w w . j a v a2 s .c om*/ CommandLineParser parser = new DefaultParser(); CommandLine cl = parser.parse(options, args); if (cl.hasOption('h')) { printHelp(System.out, options); return; } MagesSiteGenerator msg = new MagesSiteGenerator(new File("."), new File(".")); String[] fileArgs = cl.getArgs(); if (fileArgs.length < 1) { msg.addTask("."); } else { for (String path : fileArgs) { msg.addTask(path); } } if (cl.hasOption("t")) { msg.setTemplate(new File(cl.getOptionValue("t"))); } if (cl.hasOption("r")) { msg.setResource(new File(cl.getOptionValue("r"))); } else { File resource = new File("Resource.properties"); if (resource.exists()) { msg.setResource(resource); } } if (cl.hasOption("p")) { msg.setPluginDir(new File(cl.getOptionValue("p"))); } if (cl.hasOption("f")) { msg.setForce(true); } msg.start(); } catch (ParseException ex) { System.err.println(ex.getMessage()); printHelp(System.err, options); } }
From source file:com.congiu.load.csv.Main.java
public static void main(String[] args) { Options opts = buildCommandLineOptions(); Configuration conf = new Configuration(); try {//from ww w . java 2 s.c o m CommandLine cmd = processArguments(opts, args); if (cmd.hasOption(OPT_HELP[0])) { printUsage(opts, new PrintWriter(System.out)); System.exit(0); } // all unprocessed arguments are files. // let's first check if they all exist for (String s : cmd.getArgs()) { if (!FSUtils.fileExists(conf, s)) { throw new Exception("File " + s + " does not exist."); } } CSVConverter converter = getCSVConverter(cmd); for (String s : cmd.getArgs()) { } } catch (Exception ex) { System.err.println("There was a problem parsing your arguments."); System.err.println(ex); printUsage(opts, new PrintWriter(System.err)); System.exit(-1); } }
From source file:it.serasoft.pdi.PDITools.java
public static void main(String[] args) throws Exception { Options opts = new Options(); opts.addOption("report", false, "Generate a report documenting the procedures under analysis"); opts.addOption("follow", true, "Values: directory, links, none"); opts.addOption("outDir", true, "Path to output directory where we will write eventual output files"); opts.addOption("srcDir", true, "Path to base directory containing the PDI processes source"); CommandLineParser parser = new DefaultParser(); CommandLine cmdLine = parser.parse(opts, args); String outDir = cmdLine.hasOption("outDir") ? cmdLine.getOptionValue("outDir") : null; String srcDir = cmdLine.hasOption("srcDir") ? cmdLine.getOptionValue("srcDir") : null; String follow = cmdLine.hasOption("follow") ? cmdLine.getOptionValue("follow") : FOLLOW_DIR; // Follow links between procedures only if required and recurseSubdir = false (DEFAULT) boolean recurseDir = follow.equals(FOLLOW_DIR); boolean followLinks = follow.equals(FOLLOW_PROCLINKS); startReadingDir(srcDir, recurseDir, followLinks); }