CommandLineOptions.java revision 260
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * See LICENSE.txt included in this distribution for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at LICENSE.txt.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
0N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/Apackage org.opensolaris.opengrok.index;
0N/A
0N/Aimport java.io.BufferedReader;
0N/Aimport java.io.IOException;
0N/Aimport java.io.InputStreamReader;
0N/Aimport java.io.PrintWriter;
0N/Aimport java.io.StringWriter;
0N/Aimport java.text.DateFormat;
0N/Aimport java.util.ArrayList;
99N/Aimport java.util.Date;
0N/Aimport java.util.List;
0N/A
0N/Apublic class CommandLineOptions {
0N/A
0N/A class Option {
0N/A
0N/A char option;
0N/A String argument;
0N/A String description;
0N/A
0N/A public Option(char opt, String arg, String descr) {
0N/A option = opt;
0N/A argument = arg;
0N/A description = descr;
0N/A }
0N/A
0N/A public String getUsage() {
0N/A StringBuilder sb = new StringBuilder();
0N/A sb.append('-');
0N/A sb.append(option);
0N/A if (argument != null) {
0N/A sb.append(' ');
0N/A sb.append(argument);
0N/A }
0N/A sb.append("\n\t");
0N/A sb.append(description);
0N/A
0N/A return sb.toString();
0N/A }
0N/A }
0N/A private List<Option> options;
0N/A
0N/A public CommandLineOptions() {
0N/A options = new ArrayList<Option>();
0N/A options.add(new Option('q', null, "Run as quietly as possible"));
0N/A options.add(new Option('v', null, "Print progress information as we go along"));
0N/A options.add(new Option('e', null, "Economical - consumes less disk space. It does not generate hyper text cross reference files offline, but will do so on demand - which could be sightly slow. It also does not generate a spelling correction database."));
0N/A options.add(new Option('c', "/path/to/ctags", "Path to Exuberant Ctags from http://ctags.sf.net by default takes the Exuberant Ctags in PATH."));
0N/A options.add(new Option('R', "/path/to/configuration", "Read configuration from the specified file"));
0N/A options.add(new Option('W', "/path/to/configuration", "Write the current configuration to the specified file (so that the web application can use the same configuration"));
0N/A options.add(new Option('U', "host:port", "Send the current configuration to the specified address (This is most likely the web-app configured with ConfigAddress)"));
0N/A options.add(new Option('P', null, "Generate a project for each of the top-level directories in source root"));
0N/A options.add(new Option('p', "/path/to/default/project", "This is the path to the project that should be selected by default in the web application. You should strip off the source root."));
0N/A options.add(new Option('Q', "on/off", "Turn on/off quick context scan. By default only the first 32k of a file is scanned, and a '[..all..]' link is inserted if the file is bigger. Activating this may slow the server down (Note: this is setting only affects the web application)"));
0N/A options.add(new Option('n', null, "Do not generate indexes, but process all other command line options"));
0N/A options.add(new Option('H', null, "Generate history cache for all external repositories"));
0N/A options.add(new Option('h', "/path/to/repository", "Generate history cache for the specified repos (absolute path from source root)"));
0N/A options.add(new Option('r', "on/off", "Turn on/off support for remote SCM systems"));
0N/A options.add(new Option('L', "path", "Path to the subdirectory in the web-application containing the requested stylesheet. The following factory-defaults exist: \"default\", \"offwhite\" and \"polished\""));
0N/A options.add(new Option('O', "on/off", "Turn on/off the optimization of the index database as part of the indexing step"));
58N/A options.add(new Option('a', "on/off", "Allow or disallow leading wildcards in a search"));
0N/A options.add(new Option('w', "webapp-context", "Context of webapp. Default is /source. If you specify a different name, make sure to rename source.war to that name."));
0N/A options.add(new Option('i', "pattern", "Ignore the named files or directories"));
0N/A options.add(new Option('A', "ext:analyzer", "Files with the named extension should be analyzed with the specified class"));
58N/A options.add(new Option('m', "number", "The maximum words to index in a file"));
99N/A options.add(new Option('S', null, "Search for \"external\" source repositories and add them"));
99N/A options.add(new Option('s', "/path/to/source/root", "The root directory of the source tree"));
99N/A options.add(new Option('d', "/path/to/data/root", "The directory where OpenGrok stores the generated data"));
99N/A options.add(new Option('?', null, "Help"));
0N/A }
0N/A
0N/A public String getCommandString() {
0N/A StringBuilder sb = new StringBuilder();
0N/A for (Option o : options) {
0N/A sb.append(o.option);
0N/A if (o.argument != null) {
0N/A sb.append(':');
0N/A }
0N/A }
0N/A return sb.toString();
0N/A }
0N/A
0N/A public String getCommandUsage(char c) {
0N/A for (Option o : options) {
0N/A if (o.option == c) {
0N/A return o.getUsage();
0N/A }
0N/A }
0N/A
0N/A return null;
0N/A }
0N/A
0N/A private void spool(BufferedReader reader, PrintWriter out, String tag) throws IOException {
0N/A String line;
0N/A while ((line = reader.readLine()) != null) {
0N/A if (line.equals(tag)) {
89N/A return;
0N/A }
89N/A out.println(line);
89N/A }
0N/A }
0N/A
0N/A public String getUsage() {
0N/A StringWriter wrt = new StringWriter();
0N/A PrintWriter out = new PrintWriter(wrt);
0N/A
0N/A out.println("Usage: opengrok.jar [options]");
0N/A for (Option o : options) {
0N/A out.println(o.getUsage());
0N/A }
0N/A
0N/A out.flush();
0N/A out.close();
0N/A
0N/A return wrt.toString();
0N/A }
0N/A
0N/A public String getManPage() throws IOException {
0N/A StringWriter wrt = new StringWriter();
0N/A PrintWriter out = new PrintWriter(wrt);
0N/A
0N/A BufferedReader reader = new BufferedReader(new InputStreamReader(
0N/A this.getClass().getResourceAsStream("opengrok.xml"), "US-ASCII"));
0N/A
0N/A String line;
0N/A spool(reader, out, "___INSERT_DATE___");
0N/A out.print("<refmiscinfo class=\"date\">");
0N/A out.print(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()));
0N/A out.println("</refmiscinfo>");
spool(reader, out, "___INSERT_USAGE___");
for (Option o : options) {
out.println("<optional><option>");
out.print(o.option);
if (o.argument != null) {
out.print(" <replaceable>");
out.print(o.argument);
out.print("</replaceable>");
}
out.println("</option></optional>");
}
spool(reader, out, "___INSERT_OPTIONS___");
for (Option o : options) {
out.print("<varlistentry><term><option>");
out.print(o.option);
out.print("</option></term><listitem><para>");
out.print(o.description);
out.println("</para></listitem></varlistentry>");
}
spool(reader, out, "___END_OF_FILE___");
out.flush();
reader.close();
return wrt.toString();
}
/**
* Print out a manual page on standard out
*
* @param argv argument vector. not used.
*/
public static void main(String[] argv) {
CommandLineOptions co = new CommandLineOptions();
try {
System.out.println(co.getManPage());
} catch (IOException exp) {
exp.printStackTrace();
System.exit(1);
}
System.exit(0);
}
}