List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:com.huangyunkun.jviff.Runner.java
public static void main(String args[]) { Options options = new Options(); options.addOption("c", "config", true, "config file"); CommandLineParser parser = new PosixParser(); try {//from w w w . j a v a 2 s .co m CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("c")) { JViff jViff = new JViff(cmd.getOptionValue("c")); jViff.run(); } else { printHelp(options); } } catch (ParseException e) { printHelp(options); } catch (IOException e) { LOGGER.error("jviff face a error", e); } }
From source file:io.github.sn0cr.rapidRunner.CommandlineInterface.java
public static void main(String[] args) { // create Options object final Options options = new Options(); // add t option // options.addOption("t", false, "display current time"); final CommandLineParser parser = new PosixParser(); try {/*from w w w . j a v a2 s .com*/ final CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("t")) { System.out.println("has option " + cmd.getOptionValue("t")); } else { System.out.println("hasn't option"); } } catch (final ParseException e) { e.printStackTrace(); } }
From source file:com.google.gwt.site.markdown.MarkDown.java
public static void main(String[] args) throws MDHelperException, TranslaterException, ParseException { CommandLine commandLine = parseArgs(args); if (commandLine.hasOption(HELP)) { printHelp();//from w w w.j a va 2 s . c o m } else { translateMarkDown(commandLine); } }
From source file:eu.scape_project.sanselan_wrapper.SanselanCli.java
public static void main(String[] args) { try {/*from ww w.j av a 2s . co m*/ Options options = new Options(); options.addOption("i", "input-file", true, "input file"); options.addOption("o", "output-file", true, "output file"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("i") && cmd.hasOption("o")) { BufferedImage inImage = SanselanWrapper.load(cmd.getOptionValue("i"), null); SanselanWrapper.convert(inImage, cmd.getOptionValue("o"), null); } else { System.out.println("usage: (-i|--input-file=) INPUT_FILE (-o|--output-file=) OUTPUT_FILE"); System.exit(1); } } catch (Exception e) { System.err.println(e); System.exit(1); } System.exit(0); }
From source file:com.contentful.generator.Main.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); Options options = constructOptions(); try {//w w w. ja v a 2s . com CommandLine line = parser.parse(options, args); if (line.hasOption("space") && line.hasOption("package") && line.hasOption("folder") && line.hasOption("token")) { new Generator().generate(line.getOptionValue("space"), line.getOptionValue("package"), line.getOptionValue("folder"), line.getOptionValue("token")); } else { usage(options); } } catch (ParseException e) { System.err.println("Parsing failed, reason: " + e.getMessage()); } }
From source file:it.anyplace.sync.relay.server.Main.java
public static void main(String[] args) throws ParseException, Exception { Options options = new Options(); options.addOption("r", "relay-server", true, "set relay server to serve for"); options.addOption("p", "port", true, "set http server port"); 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;/* w w w. j av a 2s . c o m*/ } int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 22080; String relayServer = firstNonNull(emptyToNull(cmd.getOptionValue("r")), "relay://localhost"); logger.info("starting http relay server :{} for relay server {}", port, relayServer); HttpRelayServer httpRelayServer = new HttpRelayServer( DeviceAddress.newBuilder().setDeviceId("relay").setAddress(relayServer).build().getSocketAddress()); httpRelayServer.start(port); httpRelayServer.join(); }
From source file:com.google.api.codegen.config.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(//from w w w . j a v a2s. c o m 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.getOptionValue("output")); }
From source file:com.opensearchserver.textextractor.Main.java
public static void main(String[] args) throws IOException, ParseException { Logger.getLogger("").setLevel(Level.WARNING); Options options = new Options(); options.addOption("h", "help", false, "print this message"); options.addOption("p", "port", true, "TCP port"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar target/oss-text-extractor.jar", options); return;/* w w w . ja va 2s . c om*/ } int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9091; UndertowJaxrsServer server = new UndertowJaxrsServer() .start(Undertow.builder().addHttpListener(port, "localhost")); server.deploy(Main.class); }
From source file:io.stpettersen.bluejpackager.BlueJPackager.java
public static void main(String[] args) { // Create the command line parser. CommandLineParser parser = new DefaultParser(); // Create the command line options. Options options = new Options(); options.addOption("h", "help", false, "Display this help information and exit."); options.addOption("v", "version", false, "Display version information and exit."); options.addOption("p", "package", true, "Package string to use."); options.addOption("m", "mainClass", true, "Main class to use."); options.addOption("cp", "classPath", true, "Class path directory."); options.addOption("r", "root", true, "Root directory."); options.addOption("l", "verbose", false, "Be verbose."); try {/*from w w w . j a va2 s . co m*/ // Parse the command line arguments. CommandLine cli = parser.parse(options, args); if (cli.hasOption("h")) displayUsage(options, 0); } catch (Exception e) { // Bad command line option occurred. System.err.println("\nError: " + e.getMessage()); displayUsage(options, 1); } }
From source file:eu.scape_project.imageio_wrapper.ImageIOCli.java
public static void main(String[] args) { try {//from w w w .j a v a2s . co m Options options = new Options(); options.addOption("i", "input-file", true, "input file"); options.addOption("o", "output-file", true, "output file"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("i") && cmd.hasOption("o")) { BufferedImage inImage = ImageIOWrapper.load(cmd.getOptionValue("i"), null); if (inImage != null) { ImageIOWrapper.convert(inImage, cmd.getOptionValue("o"), null); } else { System.out.println("Unsuported input image file format!"); System.exit(1); } } else { System.out.println("usage: (-i|--input-file=) INPUT_FILE (-o|--output-file=) OUTPUT_FILE"); System.exit(1); } } catch (Exception e) { System.err.println(e); System.exit(1); } System.exit(0); }