1 /***
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.cli;
18
19 /***
20 * A sample program shpwing the use of Options and the HelpFormatter class
21 *
22 * @author Slawek Zachcial
23 **/
24 public class HelpFormatterExamples
25 {
26
27
28
29
30 public static void main( String[] args )
31 {
32 System.out.println("\n#\n# 'man' example\n#");
33 manExample();
34
35
36
37
38
39
40 }
41
42 static void manExample()
43 {
44 String cmdLine =
45 "man [-c|-f|-k|-w|-tZT device] [-adlhu7V] [-Mpath] [-Ppager] [-Slist] " +
46 "[-msystem] [-pstring] [-Llocale] [-eextension] [section] page ...";
47 Options opts =
48 new Options().
49 addOption("a", "all", false, "find all matching manual pages.").
50 addOption("d", "debug", false, "emit debugging messages.").
51 addOption("e", "extension", false, "limit search to extension type 'extension'.").
52 addOption("f", "whatis", false, "equivalent to whatis.").
53 addOption("k", "apropos", false, "equivalent to apropos.").
54 addOption("w", "location", false, "print physical location of man page(s).").
55 addOption("l", "local-file", false, "interpret 'page' argument(s) as local filename(s)").
56 addOption("u", "update", false, "force a cache consistency check.").
57
58 addOption("r", "prompt", true, "provide 'less' pager with prompt.").
59 addOption("c", "catman", false, "used by catman to reformat out of date cat pages.").
60 addOption("7", "ascii", false, "display ASCII translation or certain latin1 chars.").
61 addOption("t", "troff", false, "use troff format pages.").
62
63 addOption("T", "troff-device", true, "use groff with selected device.").
64 addOption("Z", "ditroff", false, "use groff with selected device.").
65 addOption("D", "default", false, "reset all options to their default values.").
66
67 addOption("M", "manpath", true, "set search path for manual pages to 'path'.").
68
69 addOption("P", "pager", true, "use program 'pager' to display output.").
70
71 addOption("S", "sections", true, "use colon separated section list.").
72
73 addOption("m", "systems", true, "search for man pages from other unix system(s).").
74
75 addOption("L", "locale", true, "defaine the locale for this particular man search.").
76
77 addOption("p", "preprocessor", true, "string indicates which preprocessor to run.\n" +
78 " e - [n]eqn p - pic t - tbl\n" +
79 " g - grap r - refer v - vgrind").
80 addOption("V", "version", false, "show version.").
81 addOption("h", "help", false, "show this usage message.");
82
83 HelpFormatter hf = new HelpFormatter();
84
85 hf.printHelp(60, cmdLine, null, opts, null);
86 }
87
88 static void bzip2Example()
89 {
90 System.out.println( "Coming soon" );
91 }
92
93 static void lsExample()
94 {
95 System.out.println( "Coming soon" );
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 }