List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:com.google.api.codegen.SynchronizerTool.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(/* ww w.j av a 2 s. c o m*/ Option.builder().longOpt("source_path").desc("The directory which contains the final code.") .hasArg().argName("SOURCE-PATH").required(true).build()); options.addOption( Option.builder().longOpt("generated_path").desc("The directory which contains the generated code.") .hasArg().argName("GENERATED-PATH").build()); options.addOption(Option.builder().longOpt("baseline_path") .desc("The directory which contains the baseline code.").hasArg().argName("BASELINE-PATH").build()); options.addOption(Option.builder().longOpt("auto_merge") .desc("If set, no GUI will be launched if merge can be completed automatically.") .argName("AUTO-MERGE").build()); options.addOption(Option.builder().longOpt("auto_resolve") .desc("Whether to enable smart conflict resolution").argName("AUTO_RESOLVE").build()); options.addOption(Option.builder().longOpt("ignore_base") .desc("If true, the baseline will be ignored and two-way merge will be used.") .argName("IGNORE_BASE").build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("CodeGeneratorTool", options); } synchronize(cl.getOptionValue("source_path"), cl.getOptionValue("generated_path"), cl.getOptionValue("baseline_path"), cl.hasOption("auto_merge"), cl.hasOption("auto_resolve"), cl.hasOption("ignore_base")); }
From source file:com.msg.wmTestHelper.CLIEntry.java
public static void main(String... args) { try {//from w ww . java2 s .c om CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(createOptions(), args); if (cmd.hasOption("h")) { printHelp(); } else { GeneratorParameter parameter = extractParameter(cmd); if (parameter.hasSufficientData()) { TestHelper testHelper = new TestHelper(); testHelper.generateTestHelper(parameter); } else { log.error("Parameters are not sufficient, exiting. " + "WMPRT folder, output folder and namespace must be set."); } } } catch (ParseException e) { log.error(e.toString()); } }
From source file:com.tomdoel.mpg2dcm.Mpg2Dcm.java
public static void main(String[] args) { try {//from w ww. jav a 2 s. co m final Options helpOptions = new Options(); helpOptions.addOption("h", false, "Print help for this application"); final DefaultParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(helpOptions, args); if (commandLine.hasOption('h')) { final String helpHeader = "Converts an mpeg2 video file to Dicom\n\n"; String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm"; final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Mpg2Dcm mpegfile dicomfile", helpHeader, helpOptions, helpFooter, true); } else { final List<String> remainingArgs = commandLine.getArgList(); if (remainingArgs.size() < 2) { throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified."); } final String mpegFileName = remainingArgs.get(0); final String dicomFileName = remainingArgs.get(1); final File mpegFile = new File(mpegFileName); final File dicomOutputFile = new File(dicomFileName); MpegFileConverter.convert(mpegFile, dicomOutputFile); } } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:fr.jamgotchian.tuplegen.core.Main.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); try {/* w ww .ja v a2s. com*/ CommandLine line = parser.parse(OPTIONS, args); if (line.hasOption("h") || !line.hasOption("c") || !line.hasOption("d")) { usage(); } File genSrcDir = new File(line.getOptionValue("d")); if (!genSrcDir.exists()) { throw new IllegalArgumentException(genSrcDir + " does not exit"); } if (!genSrcDir.isDirectory()) { throw new IllegalArgumentException(genSrcDir + " should be a directory"); } File cfgFile = new File(line.getOptionValue("c")); if (!cfgFile.exists()) { throw new IllegalArgumentException(cfgFile + " does not exist"); } TupleGen generator = new TupleGen(); generator.generate(cfgFile, genSrcDir, false, LOGGER); } catch (Throwable t) { t.printStackTrace(); } }
From source file:info.jejking.opengeodb.neo4j.importer.ImporterRunner.java
/** * Runs the importer./*from w w w . j a v a 2 s . c o m*/ * * <p> * Supply the following arguments: * </p> * <ol> * <li>path to the tab-delimited place file</li> * <li>path to the tab-delimited postal code file</li> * <li>path to the directory where the Graph DB is to be found/created</li> * </ol> * * @param args * as above * @throws IOException * @throws ParseException */ public static void main(String[] args) throws IOException, ParseException { initOptions(); CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("opengeodb2neo4j", options); } else { String placeFilePath = commandLine.getOptionValue("p"); String zipFilePath = commandLine.getOptionValue("z"); String neo4jDirPath = commandLine.getOptionValue("n"); Importer importer = new Importer(); importer.doImport(placeFilePath, zipFilePath, neo4jDirPath); } }
From source file:com.opengamma.bbg.replay.BloombergTicksCollectorLauncher.java
/** * Starts the Bloomberg Ticks Collector. * /* w ww. j a v a2 s.com*/ * @param args Not needed */ public static void main(String[] args) { // CSIGNORE int duration = 0; CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("d", "duration", true, "minutes to run"); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("duration")) { duration = Integer.parseInt(cmd.getOptionValue("duration")); } } catch (ParseException exp) { s_logger.error("Option parsing failed: {}", exp.getMessage()); return; } BloombergTicksCollectorLauncher launcher = new BloombergTicksCollectorLauncher(); launcher.run(); if (duration > 0) { try { Thread.sleep(duration * 60 * 1000); } catch (InterruptedException e) { } launcher.exit(); } }
From source file:com.google.api.codegen.grpcmetadatagen.GrpcMetadataGeneratorTool.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 a2 s . co m*/ Option.builder().longOpt("service_yaml").desc("The service YAML configuration file or files.") .hasArg().argName("SERVICE-YAML").required(true).build()); options.addOption( Option.builder("i").longOpt("input").desc("The input directory containing the gRPC package.") .hasArg().argName("INPUT-DIR").required(true).build()); options.addOption( Option.builder("o").longOpt("output").desc("The directory in which to output the generated config.") .hasArg().argName("OUTPUT-DIR").required(true).build()); options.addOption( Option.builder("l").longOpt("language").desc("The language for which to generate package metadata.") .hasArg().argName("LANGUAGE").required(true).build()); options.addOption(Option.builder("c").longOpt("metadata_config") .desc("The YAML file configuring the package metadata.").hasArg().argName("METADATA-CONFIG") .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.getOptionValues("service_yaml"), cl.getOptionValue("input"), cl.getOptionValue("output"), cl.getOptionValue("language"), cl.getOptionValue("metadata_config")); }
From source file:demo.learn.shiro.tool.PasswordEncryptionTool.java
/** * Main method./*from w ww. j a v a2 s. c om*/ * @param args Requires a plain text password. */ @SuppressWarnings("static-access") public static void main(String[] args) { String plainTextPassword = "root"; Option p = OptionBuilder.withArgName("password").hasArg().withDescription("plain text password") .isRequired(false).create('p'); Options options = new Options(); options.addOption(p); try { CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("p")) { plainTextPassword = cmd.getOptionValue("p"); } } catch (ParseException pe) { String cmdLineSyntax = "java -cp %CLASSPATH% demo.learn.shiro.tool.PasswordEncryptionTool"; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(cmdLineSyntax, options, false); return; } final RandomNumberGenerator rng = new SecureRandomNumberGenerator(); final ByteSource salt = rng.nextBytes(); final String saltBase64 = Base64.encodeToString(salt.getBytes()); final String hashedPasswordBase64 = new Sha256Hash(plainTextPassword, salt, S.HASH_ITER).toBase64(); System.out.print("-p " + plainTextPassword); System.out.print(" -h " + hashedPasswordBase64); System.out.println(" -s " + saltBase64); }
From source file:com.floragunn.searchguard.tools.Hasher.java
public static void main(final String[] args) { final Options options = new Options(); final HelpFormatter formatter = new HelpFormatter(); options.addOption(//w w w. j a v a2 s.c o m Option.builder("p").argName("password").hasArg().desc("Cleartext password to hash").build()); options.addOption(Option.builder("env").argName("name environment variable").hasArg() .desc("name environment variable to read password from").build()); final CommandLineParser parser = new DefaultParser(); try { final CommandLine line = parser.parse(options, args); if (line.hasOption("p")) { System.out.println(hash(line.getOptionValue("p").getBytes("UTF-8"))); } else if (line.hasOption("env")) { final String pwd = System.getenv(line.getOptionValue("env")); if (pwd == null || pwd.isEmpty()) { throw new Exception("No environment variable '" + line.getOptionValue("env") + "' set"); } System.out.println(hash(pwd.getBytes("UTF-8"))); } else { final Console console = System.console(); if (console == null) { throw new Exception("Cannot allocate a console"); } final char[] passwd = console.readPassword("[%s]", "Password:"); System.out.println(hash(new String(passwd).getBytes("UTF-8"))); } } catch (final Exception exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); formatter.printHelp("hasher.sh", options, true); System.exit(-1); } }
From source file:com.redhat.akashche.keystoregen.Launcher.java
public static void main(String[] args) throws Exception { try {// w w w .j av a 2 s .c o m CommandLine cline = new GnuParser().parse(OPTIONS, args); if (cline.hasOption(VERSION_OPTION)) { out.println(VERSION); } else if (cline.hasOption(HELP_OPTION)) { throw new ParseException("Printing help page:"); } else if (0 == cline.getArgs().length && cline.hasOption(CONFIG_OPTION) && cline.hasOption(OUTPUT_OPTION)) { KeystoreConfig conf = parseConf(cline.getOptionValue(CONFIG_OPTION)); KeyStore ks = new KeystoreGenerator().generate(conf); writeKeystore(conf, ks, cline.getOptionValue(OUTPUT_OPTION)); } else { throw new ParseException("Incorrect arguments received!"); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); out.println(e.getMessage()); out.println(VERSION); formatter.printHelp("java -jar keystoregen.jar -c config.json -o output.p12", OPTIONS); } }