001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.commons.cli;
017:
018: /**
019: * A sample program shpwing the use of Options and the HelpFormatter class
020: *
021: * @author Slawek Zachcial
022: **/
023: public class HelpFormatterExamples {
024: // --------------------------------------------------------------- Constants
025:
026: // ------------------------------------------------------------------ Static
027:
028: public static void main(String[] args) {
029: System.out.println("\n#\n# 'man' example\n#");
030: manExample();
031: /*
032: System.out.println("\n#\n# 'bzip2' example\n#");
033: bzip2Example();
034: System.out.println("\n#\n# 'ls' example\n#");
035: lsExample();
036: */
037: }
038:
039: static void manExample() {
040: String cmdLine = "man [-c|-f|-k|-w|-tZT device] [-adlhu7V] [-Mpath] [-Ppager] [-Slist] "
041: + "[-msystem] [-pstring] [-Llocale] [-eextension] [section] page ...";
042: Options opts = new Options()
043: .addOption("a", "all", false,
044: "find all matching manual pages.")
045: .addOption("d", "debug", false,
046: "emit debugging messages.")
047: .addOption("e", "extension", false,
048: "limit search to extension type 'extension'.")
049: .addOption("f", "whatis", false,
050: "equivalent to whatis.")
051: .addOption("k", "apropos", false,
052: "equivalent to apropos.")
053: .addOption("w", "location", false,
054: "print physical location of man page(s).")
055: .addOption("l", "local-file", false,
056: "interpret 'page' argument(s) as local filename(s)")
057: .addOption("u", "update", false,
058: "force a cache consistency check.")
059: .
060: //FIXME - should generate -r,--prompt string
061: addOption("r", "prompt", true,
062: "provide 'less' pager with prompt.")
063: .addOption("c", "catman", false,
064: "used by catman to reformat out of date cat pages.")
065: .addOption("7", "ascii", false,
066: "display ASCII translation or certain latin1 chars.")
067: .addOption("t", "troff", false,
068: "use troff format pages.")
069: .
070: //FIXME - should generate -T,--troff-device device
071: addOption("T", "troff-device", true,
072: "use groff with selected device.")
073: .addOption("Z", "ditroff", false,
074: "use groff with selected device.")
075: .addOption("D", "default", false,
076: "reset all options to their default values.")
077: .
078: //FIXME - should generate -M,--manpath path
079: addOption("M", "manpath", true,
080: "set search path for manual pages to 'path'.")
081: .
082: //FIXME - should generate -P,--pager pager
083: addOption("P", "pager", true,
084: "use program 'pager' to display output.")
085: .
086: //FIXME - should generate -S,--sections list
087: addOption("S", "sections", true,
088: "use colon separated section list.")
089: .
090: //FIXME - should generate -m,--systems system
091: addOption("m", "systems", true,
092: "search for man pages from other unix system(s).")
093: .
094: //FIXME - should generate -L,--locale locale
095: addOption("L", "locale", true,
096: "defaine the locale for this particular man search.")
097: .
098: //FIXME - should generate -p,--preprocessor string
099: addOption(
100: "p",
101: "preprocessor",
102: true,
103: "string indicates which preprocessor to run.\n"
104: + " e - [n]eqn p - pic t - tbl\n"
105: + " g - grap r - refer v - vgrind")
106: .addOption("V", "version", false, "show version.")
107: .addOption("h", "help", false,
108: "show this usage message.");
109:
110: HelpFormatter hf = new HelpFormatter();
111: //hf.printHelp(cmdLine, opts);
112: hf.printHelp(60, cmdLine, null, opts, null);
113: }
114:
115: static void bzip2Example() {
116: System.out.println("Coming soon");
117: }
118:
119: static void lsExample() {
120: System.out.println("Coming soon");
121: }
122:
123: // -------------------------------------------------------------- Attributes
124:
125: // ------------------------------------------------------------ Constructors
126:
127: // ------------------------------------------------------------------ Public
128:
129: // --------------------------------------------------------------- Protected
130:
131: // ------------------------------------------------------- Package protected
132:
133: // ----------------------------------------------------------------- Private
134:
135: // ----------------------------------------------------------- Inner classes
136:
137: }
|