List of usage examples for org.apache.commons.cli Option getArgName
public String getArgName()
From source file:com.netflix.suro.SuroServer.java
public static void main(String[] args) throws IOException { final AtomicReference<Injector> injector = new AtomicReference<Injector>(); try {/* www . j a v a 2 s . c om*/ // Parse the command line Options options = createOptions(); final CommandLine line = new BasicParser().parse(options, args); // Load the properties file final Properties properties = new Properties(); if (line.hasOption('p')) { properties.load(new FileInputStream(line.getOptionValue('p'))); } // Bind all command line options to the properties with prefix "SuroServer." for (Option opt : line.getOptions()) { String name = opt.getOpt(); String value = line.getOptionValue(name); String propName = PROP_PREFIX + opt.getArgName(); if (propName.equals(DynamicPropertyRoutingMapConfigurator.ROUTING_MAP_PROPERTY)) { properties.setProperty(DynamicPropertyRoutingMapConfigurator.ROUTING_MAP_PROPERTY, FileUtils.readFileToString(new File(value))); } else if (propName.equals(DynamicPropertySinkConfigurator.SINK_PROPERTY)) { properties.setProperty(DynamicPropertySinkConfigurator.SINK_PROPERTY, FileUtils.readFileToString(new File(value))); } else if (propName.equals(DynamicPropertyInputConfigurator.INPUT_CONFIG_PROPERTY)) { properties.setProperty(DynamicPropertyInputConfigurator.INPUT_CONFIG_PROPERTY, FileUtils.readFileToString(new File(value))); } else { properties.setProperty(propName, value); } } create(injector, properties); injector.get().getInstance(LifecycleManager.class).start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { Closeables.close(injector.get().getInstance(LifecycleManager.class), true); } catch (IOException e) { // do nothing because Closeables.close will swallow IOException } } }); waitForShutdown(getControlPort(properties)); } catch (Throwable e) { System.err.println("SuroServer startup failed: " + e.getMessage()); System.exit(-1); } finally { Closeables.close(injector.get().getInstance(LifecycleManager.class), true); } }
From source file:com.temenos.interaction.rimdsl.generator.launcher.Main.java
public static void main(String[] args) { // handle command line options final Options options = new Options(); OptionBuilder.withArgName("src"); OptionBuilder.withDescription("Model source"); OptionBuilder.hasArg();/* w ww.j a va2s . c om*/ OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optSrc = OptionBuilder.create("src"); OptionBuilder.withArgName("targetdir"); OptionBuilder.withDescription("Generator target directory"); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optTargetDir = OptionBuilder.create("targetdir"); options.addOption(optSrc); options.addOption(optTargetDir); // create the command line parser final CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (final ParseException exp) { System.err.println("Parsing arguments failed. Reason: " + exp); wrongCall(options); return; } // execute the generator Injector injector = new RIMDslStandaloneSetup().createInjectorAndDoEMFRegistration(); Generator generator = injector.getInstance(Generator.class); File srcFile = new File(line.getOptionValue(optSrc.getArgName())); if (srcFile.exists()) { boolean result = false; if (srcFile.isDirectory()) { result = generator.runGeneratorDir(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } else { result = generator.runGenerator(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } System.out.println("Code generation finished [" + result + "]"); } else { System.out.println("Src dir not found."); } }
From source file:com.temenos.interaction.rimdsl.generator.launcher.MainSpringPRD.java
public static void main(String[] args) { // handle command line options final Options options = new Options(); OptionBuilder.withArgName("src"); OptionBuilder.withDescription("Model source"); OptionBuilder.hasArg();/*from w w w .j a va2 s .c o m*/ OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optSrc = OptionBuilder.create("src"); OptionBuilder.withArgName("targetdir"); OptionBuilder.withDescription("Generator target directory"); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optTargetDir = OptionBuilder.create("targetdir"); options.addOption(optSrc); options.addOption(optTargetDir); // create the command line parser final CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (final ParseException exp) { System.err.println("Parsing arguments failed. Reason: " + exp); wrongCall(options); return; } // execute the generator Injector injector = new RIMDslStandaloneSetupSpringPRD().createInjectorAndDoEMFRegistration(); Generator generator = injector.getInstance(Generator.class); File srcFile = new File(line.getOptionValue(optSrc.getArgName())); if (srcFile.exists()) { boolean result = false; if (srcFile.isDirectory()) { result = generator.runGeneratorDir(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } else { result = generator.runGenerator(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } System.out.println("Code generation finished [" + result + "]"); } else { System.out.println("Src dir not found."); } }
From source file:be.dnsbelgium.rdap.client.ManGenerator.java
private static String getOptionString(Option option) { return String.format("%s%s%s", option.getOpt() == null ? "" : "-" + option.getOpt() + " ", option.getLongOpt() == null ? "" : "--" + option.getLongOpt() + " ", option.hasArg() ? "<" + option.getArgName() + ">" : "" ).trim();// ww w . j a va2s . c o m }
From source file:dk.hippogrif.prettyxml.app.Main.java
private static void optionUsage(PrintStream ps) { for (Iterator iter = optionList.iterator(); iter.hasNext();) { Option option = (Option) iter.next(); ps.print(" -" + option.getOpt()); String spaces = " "; int i = 0; if (option.hasArg()) { ps.print(" " + option.getArgName()); i = option.getArgName().length() + 1; }/*from ww w .j ava 2 s . c o m*/ ps.print(spaces.substring(i)); ps.println(option.getDescription()); } }
From source file:de.haber.xmind2latex.cli.CliParameters.java
/** * Helper method that throws a {@link ParseException} if parameter arguments are missing. * /*from www. j a v a 2 s .co m*/ * @param cmd the concrete {@link CommandLine} * @param param name of the parameter that is to be validated * @param opts configured {@link Options} * @throws ParseException if the number of arguments does not correspond to the expected number of arguments for the given parameter */ public static void validateNumberOfArguments(CommandLine cmd, char param, Options opts) throws ParseException { Integer numberOfArgs = param2arguments.get(param); String[] tmp = cmd.getOptionValues(param); if (numberOfArgs != null && tmp != null && tmp.length % numberOfArgs != 0) { Option o = opts.getOption(Character.toString(param)); String name = o.getLongOpt() != null ? o.getLongOpt() : Character.toString(param); throw new ParseException("Invalid amount of arguments for parameter " + name + ": <" + o.getArgName() + ">. Description: " + o.getDescription()); } }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.app.Main.java
private static void parseCli(String[] args) { CommandLineParser parser = new PosixParser(); try {/*from w w w .j a va 2s .c o m*/ CommandLine cmd = parser.parse(options, args); // Show usage, ignore other parameters and quit if (cmd.hasOption('h')) { usage(); logger.debug("Help called, main() exit."); System.exit(0); } if (cmd.hasOption('d')) { // Activate debug markup only - does not affect logging! debugMarkupOutput = true; } if (cmd.hasOption('m')) { exportMarkup = true; } if (cmd.hasOption('t')) { title = cmd.getOptionValue('t'); } if (cmd.hasOption('f')) { filename = cmd.getOptionValue('f'); } if (cmd.hasOption('n')) { exportMarkup = true; // implicit markup export noMobiConversion = true; } if (cmd.hasOption('i')) { String[] inputValues = cmd.getOptionValues('i'); for (String inputValue : inputValues) { inputPaths.add(Paths.get(inputValue)); } } else { logger.error("You have to specify an inputPath file or directory!"); usage(); System.exit(1); } if (cmd.hasOption('o')) { String outputDirectory = cmd.getOptionValue('o'); outputPath = Paths.get(outputDirectory).toAbsolutePath(); logger.debug("Output path: " + outputPath.toAbsolutePath().toString()); if (!Files.isDirectory(outputPath) && Files.isRegularFile(outputPath)) { logger.error("Given output directory is a file! Exiting..."); System.exit(1); } if (!Files.exists(outputPath)) { Files.createDirectory(outputPath); } if (!Files.isWritable(outputPath)) { logger.error("Given output directory is not writable! Exiting..."); logger.debug(outputPath.toAbsolutePath().toString()); System.exit(1); } logger.debug("Output path: " + outputPath.toAbsolutePath().toString()); } else { // Set default output directory if none is given outputPath = workingDirectory; } // If set, replace LaTeX Formulas with PNG images, created by if (cmd.hasOption("r")) { logger.debug("Picture Flag set"); replaceWithPictures = true; } if (cmd.hasOption("u")) { logger.debug("Use calibre instead of kindlegen"); useCalibreInsteadOfKindleGen = true; } // Executable configuration LatexToHtmlConverter latexToHtmlConverter = (LatexToHtmlConverter) applicationContext .getBean("latex2html-converter"); if (cmd.hasOption(latexToHtmlConverter.getExecOption().getOpt())) { String execValue = cmd.getOptionValue(latexToHtmlConverter.getExecOption().getOpt()); logger.info("LaTeX to HTML Executable argument was given: " + execValue); Path execPath = Paths.get(execValue); latexToHtmlConverter.setExecPath(execPath); } String htmlToMobiConverterBean = KINDLEGEN_HTML2MOBI_CONVERTER; if (useCalibreInsteadOfKindleGen) { htmlToMobiConverterBean = CALIBRE_HTML2MOBI_CONVERTER; } HtmlToMobiConverter htmlToMobiConverter = (HtmlToMobiConverter) applicationContext .getBean(htmlToMobiConverterBean); Option htmlToMobiOption = htmlToMobiConverter.getExecOption(); if (cmd.hasOption(htmlToMobiOption.getOpt())) { String execValue = cmd.getOptionValue(htmlToMobiOption.getOpt()); logger.info("HTML to Mobi Executable argument was given: " + execValue); try { Path execPath = Paths.get(execValue); htmlToMobiConverter.setExecPath(execPath); } catch (InvalidPathException e) { logger.error("Invalid path given for --" + htmlToMobiOption.getLongOpt() + " <" + htmlToMobiOption.getArgName() + ">"); logger.error("I will try to use your system's PATH variable..."); } } } catch (MissingOptionException m) { Iterator<String> missingOptionsIterator = m.getMissingOptions().iterator(); while (missingOptionsIterator.hasNext()) { logger.error("Missing required options: " + missingOptionsIterator.next() + "\n"); } usage(); System.exit(1); } catch (MissingArgumentException a) { logger.error("Missing required argument for option: " + a.getOption().getOpt() + "/" + a.getOption().getLongOpt() + "<" + a.getOption().getArgName() + ">"); usage(); System.exit(2); } catch (ParseException e) { logger.error("Error parsing command line arguments, exiting..."); logger.error(e.getMessage(), e); System.exit(3); } catch (IOException e) { logger.error("Error creating output path at " + outputPath.toAbsolutePath().toString()); logger.error(e.getMessage(), e); logger.error("Exiting..."); System.exit(4); } }
From source file:com.github.horrorho.inflatabledonkey.args.PropertyLoader.java
void testIntegers(Option option) { if (!"int".equals(option.getArgName())) { return;/*from ww w . jav a 2s . c o m*/ } option.getValuesList().forEach(v -> testInteger(option.getLongOpt(), v)); }
From source file:com.marklogic.contentpump.utilities.CommandlineOption.java
public CommandlineOption(Option opt) throws IllegalArgumentException { super(opt.getOpt(), opt.hasArg(), opt.getDescription()); this.setLongOpt(opt.getLongOpt()); this.setRequired(opt.isRequired()); this.setArgName(opt.getArgName()); this.setArgs(opt.getArgs()); this.setOptionalArg(opt.hasOptionalArg()); this.setType(opt.getType()); this.setValueSeparator(opt.getValueSeparator()); }
From source file:com.engineering.ses.spell.clientstubj.cmdclient.CommandClient.java
/*************************************************************************** * Show help text /*w w w. j a va2s . c o m*/ **************************************************************************/ private void showHelp() { System.out.println("Usage: java -jar <jarfile> [options]"); System.out.println(); System.out.println("Available options:"); for (Object obj : m_optionsDef.getOptions()) { Option opt = (Option) obj; System.out.println( " -" + opt.getArgName() + ", --" + opt.getLongOpt() + " : " + opt.getDescription()); } System.out.println(); }