KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > cli > HelpFormatterExamples


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  *
8  * $Id: HelpFormatterExamples.java,v 1.2 2002/05/17 11:44:32 jstrachan Exp $
9  */

10 package org.apache.commons.cli;
11
12 /**
13  * A sample program shpwing the use of Options and the HelpFormatter class
14  *
15  * @author Slawek Zachcial
16  **/

17 public class HelpFormatterExamples
18 {
19    // --------------------------------------------------------------- Constants
20

21    // ------------------------------------------------------------------ Static
22

23    public static void main( String JavaDoc[] args )
24    {
25       System.out.println("\n#\n# 'man' example\n#");
26       manExample();
27 /*
28       System.out.println("\n#\n# 'bzip2' example\n#");
29       bzip2Example();
30       System.out.println("\n#\n# 'ls' example\n#");
31       lsExample();
32 */

33    }
34
35    static void manExample()
36    {
37       String JavaDoc cmdLine =
38          "man [-c|-f|-k|-w|-tZT device] [-adlhu7V] [-Mpath] [-Ppager] [-Slist] " +
39          "[-msystem] [-pstring] [-Llocale] [-eextension] [section] page ...";
40       Options opts =
41          new Options().
42          addOption("a", "all", false, "find all matching manual pages.").
43          addOption("d", "debug", false, "emit debugging messages.").
44          addOption("e", "extension", false, "limit search to extension type 'extension'.").
45          addOption("f", "whatis", false, "equivalent to whatis.").
46          addOption("k", "apropos", false, "equivalent to apropos.").
47          addOption("w", "location", false, "print physical location of man page(s).").
48          addOption("l", "local-file", false, "interpret 'page' argument(s) as local filename(s)").
49          addOption("u", "update", false, "force a cache consistency check.").
50          //FIXME - should generate -r,--prompt string
51
addOption("r", "prompt", true, "provide 'less' pager with prompt.").
52          addOption("c", "catman", false, "used by catman to reformat out of date cat pages.").
53          addOption("7", "ascii", false, "display ASCII translation or certain latin1 chars.").
54          addOption("t", "troff", false, "use troff format pages.").
55          //FIXME - should generate -T,--troff-device device
56
addOption("T", "troff-device", true, "use groff with selected device.").
57          addOption("Z", "ditroff", false, "use groff with selected device.").
58          addOption("D", "default", false, "reset all options to their default values.").
59          //FIXME - should generate -M,--manpath path
60
addOption("M", "manpath", true, "set search path for manual pages to 'path'.").
61          //FIXME - should generate -P,--pager pager
62
addOption("P", "pager", true, "use program 'pager' to display output.").
63          //FIXME - should generate -S,--sections list
64
addOption("S", "sections", true, "use colon separated section list.").
65          //FIXME - should generate -m,--systems system
66
addOption("m", "systems", true, "search for man pages from other unix system(s).").
67          //FIXME - should generate -L,--locale locale
68
addOption("L", "locale", true, "defaine the locale for this particular man search.").
69          //FIXME - should generate -p,--preprocessor string
70
addOption("p", "preprocessor", true, "string indicates which preprocessor to run.\n" +
71                                                  " e - [n]eqn p - pic t - tbl\n" +
72                                                  " g - grap r - refer v - vgrind").
73          addOption("V", "version", false, "show version.").
74          addOption("h", "help", false, "show this usage message.");
75
76       HelpFormatter hf = new HelpFormatter();
77       //hf.printHelp(cmdLine, opts);
78
hf.printHelp(60, cmdLine, null, opts, null);
79    }
80
81    static void bzip2Example()
82    {
83       System.out.println( "Coming soon" );
84    }
85
86    static void lsExample()
87    {
88       System.out.println( "Coming soon" );
89    }
90
91
92    // -------------------------------------------------------------- Attributes
93

94    // ------------------------------------------------------------ Constructors
95

96    // ------------------------------------------------------------------ Public
97

98    // --------------------------------------------------------------- Protected
99

100    // ------------------------------------------------------- Package protected
101

102    // ----------------------------------------------------------------- Private
103

104    // ----------------------------------------------------------- Inner classes
105

106 }
107
Popular Tags