List of usage examples for org.apache.commons.cli HelpFormatter setSyntaxPrefix
public void setSyntaxPrefix(String prefix)
From source file:org.ovirt.sdk.python.Tool.java
public void run(String[] args) throws Exception { // Create the command line options: Options options = new Options(); // Options for the locations of files and directories: options.addOption(Option.builder().longOpt(MODEL_OPTION) .desc("The directory or .jar file containing the source model files.").type(File.class) .required(true).hasArg(true).argName("DIRECTORY|JAR").build()); // Options for the location of the generated Python sources: options.addOption(Option.builder().longOpt(OUT_OPTION) .desc("The directory where the generated Python source will be created.").type(File.class) .required(false).hasArg(true).argName("DIRECTORY").build()); // Option to specify the version number: options.addOption(Option.builder().longOpt(VERSION_OPTION) .desc("The the version number of the SDK, for example \"4.0.0.a0\".").type(File.class) .required(true).hasArg(true).argName("VERSION").build()); // Parse the command line: CommandLineParser parser = new DefaultParser(); CommandLine line = null;//from w ww. jav a2 s . c o m try { line = parser.parse(options, args); } catch (ParseException exception) { HelpFormatter formatter = new HelpFormatter(); formatter.setSyntaxPrefix("Usage: "); formatter.printHelp("python-tool [OPTIONS]", options); System.exit(1); } // Extract the locations of files and directories from the command line: File modelFile = (File) line.getParsedOptionValue(MODEL_OPTION); File outDir = (File) line.getParsedOptionValue(OUT_OPTION); // Extract the version number: String version = line.getOptionValue(VERSION_OPTION); // The version will usually come from the root POM of the project, where it will the "-SNAPSHOT" suffix for non // release versions. We need to remove that suffix. version = version.replaceAll("-SNAPSHOT$", ""); // Analyze the model files: Model model = new Model(); ModelAnalyzer modelAnalyzer = new ModelAnalyzer(); modelAnalyzer.setModel(model); modelAnalyzer.analyzeSource(modelFile); // Add the built-in types: builtinTypes.addBuiltinTypes(model); // Configure the object used to generate names: pythonNames.setVersion(version); // Run the generators: if (outDir != null) { FileUtils.forceMkdir(outDir); for (PythonGenerator generator : generators) { generator.setOut(outDir); generator.generate(model); } } }
From source file:org.ovirt.sdk.ruby.Tool.java
public void run(String[] args) throws Exception { // Create the command line options: Options options = new Options(); // Options for the locations of files and directories: options.addOption(Option.builder().longOpt(MODEL_OPTION) .desc("The directory or .jar file containing the source model files.").type(File.class) .required(true).hasArg(true).argName("DIRECTORY|JAR").build()); // Options for the location of the generated Ruby sources: options.addOption(Option.builder().longOpt(OUT_OPTION) .desc("The directory where the generated Ruby source will be created.").type(File.class) .required(false).hasArg(true).argName("DIRECTORY").build()); // Option to specify the version number of the gem: options.addOption(Option.builder().longOpt(VERSION_OPTION) .desc("The the version number of the SDK, for example \"4.0.0.Alpha0\".").type(File.class) .required(true).hasArg(true).argName("VERSION").build()); // Parse the command line: CommandLineParser parser = new DefaultParser(); CommandLine line = null;// www. ja v a2 s . com try { line = parser.parse(options, args); } catch (ParseException exception) { HelpFormatter formatter = new HelpFormatter(); formatter.setSyntaxPrefix("Usage: "); formatter.printHelp("ruby-tool [OPTIONS]", options); System.exit(1); } // Extract the locations of files and directories from the command line: File modelFile = (File) line.getParsedOptionValue(MODEL_OPTION); File outDir = (File) line.getParsedOptionValue(OUT_OPTION); // Extract the version of the: String version = line.getOptionValue(VERSION_OPTION); // The version will usually come from the root POM of the project, where it will use upper case for suffixes // like "Alpha" or "Beta". In addition it will have the "-SNAPSHOT" suffix for non release versions. We need // to remove the "-SNAPSHOT" suffix, and convert the result to lower case, as the common practice for Ruby // is to use "alpha" or "beta", lower case. version = version.replaceAll("-SNAPSHOT$", "").toLowerCase(); // Analyze the model files: Model model = new Model(); ModelAnalyzer modelAnalyzer = new ModelAnalyzer(); modelAnalyzer.setModel(model); modelAnalyzer.analyzeSource(modelFile); // Add the built-in types: builtinTypes.addBuiltinTypes(model); // Configure the object used to generate names: rubyNames.setVersion(version); // Run the generators: if (outDir != null) { FileUtils.forceMkdir(outDir); for (RubyGenerator generator : generators) { generator.setOut(outDir); generator.generate(model); } } }
From source file:org.parallelj.launching.transport.tcp.command.AbstractLaunchTcpCommand.java
@Override public String getHelp() { final Writer writer = new StringWriter(); final PrintWriter printWriter = new PrintWriter(writer); final Options options = new Options(); for (IOption ioption : this.getOptions()) { options.addOption(ioption.getOption()); }/*w w w. j a v a 2 s.com*/ final HelpFormatter formatter = new HelpFormatter(); formatter.setSyntaxPrefix(" "); final Comparator<Option> comparator = new Comparator<Option>() { public int compare(final Option option1, final Option option2) { if (option1.isRequired()) { return -1; } if (option2.isRequired()) { return 1; } return 0; } }; formatter.setOptionComparator(comparator); printWriter.print(getUsage() + TcpIpHandlerAdapter.ENDLINE); formatter.printHelp(printWriter, DEFAULT_WIDTH, getType(), null, options, DEFAULT_LEFT_PAD, DEFAULT_DESC_PAD, null, true); printWriter.flush(); try { writer.flush(); } catch (IOException e) { LaunchingMessageKind.EREMOTE0009.format(e); } return writer.toString(); }
From source file:org.ppojo.HelpPrinter.java
public static void print(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.setSyntaxPrefix(""); formatter.setOptionComparator(Comparator.instance); formatter.setWidth(140);/*ww w . j a va2 s . com*/ formatter.printHelp("usage: papa-pojo -sources <sources folder> [options]", options); }