File: HelpFormatterExamples.java

package info (click to toggle)
jython 2.7.2%2Brepack1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 62,676 kB
  • sloc: python: 640,908; java: 306,458; xml: 1,984; sh: 522; ansic: 126; makefile: 76
file content (106 lines) | stat: -rw-r--r-- 4,787 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included with this distribution in
 * the LICENSE file.
 * 
 * $Id: HelpFormatterExamples.java 2662 2006-02-18 14:20:33Z otmarhumbel $
 */
package org.apache.commons.cli;

/** 
 * A sample program shpwing the use of Options and the HelpFormatter class 
 *
 * @author Slawek Zachcial
 **/
public class HelpFormatterExamples
{
   // --------------------------------------------------------------- Constants

   // ------------------------------------------------------------------ Static

   public static void main( String[] args )
   {
      System.out.println("\n#\n# 'man' example\n#");
      manExample();
/*
      System.out.println("\n#\n# 'bzip2' example\n#");
      bzip2Example();
      System.out.println("\n#\n# 'ls' example\n#");
      lsExample();
*/
   }

   static void manExample()
   {
      String cmdLine =
         "man [-c|-f|-k|-w|-tZT device] [-adlhu7V] [-Mpath] [-Ppager] [-Slist] " +
         "[-msystem] [-pstring] [-Llocale] [-eextension] [section] page ...";
      Options opts =
         new Options().
         addOption("a", "all",            false, "find all matching manual pages.").
         addOption("d", "debug",          false, "emit debugging messages.").
         addOption("e", "extension",      false, "limit search to extension type 'extension'.").
         addOption("f", "whatis",         false, "equivalent to whatis.").
         addOption("k", "apropos",        false, "equivalent to apropos.").
         addOption("w", "location",       false, "print physical location of man page(s).").
         addOption("l", "local-file",     false, "interpret 'page' argument(s) as local filename(s)").
         addOption("u", "update",         false, "force a cache consistency check.").
         //FIXME - should generate -r,--prompt string
         addOption("r", "prompt",         true,  "provide 'less' pager with prompt.").
         addOption("c", "catman",         false, "used by catman to reformat out of date cat pages.").
         addOption("7", "ascii",          false, "display ASCII translation or certain latin1 chars.").
         addOption("t", "troff",          false, "use troff format pages.").
         //FIXME - should generate -T,--troff-device device
         addOption("T", "troff-device",   true,  "use groff with selected device.").
         addOption("Z", "ditroff",        false, "use groff with selected device.").
         addOption("D", "default",        false, "reset all options to their default values.").
         //FIXME - should generate -M,--manpath path
         addOption("M", "manpath",        true,  "set search path for manual pages to 'path'.").
         //FIXME - should generate -P,--pager pager
         addOption("P", "pager",          true,  "use program 'pager' to display output.").
         //FIXME - should generate -S,--sections list
         addOption("S", "sections",       true,  "use colon separated section list.").
         //FIXME - should generate -m,--systems system
         addOption("m", "systems",        true,  "search for man pages from other unix system(s).").
         //FIXME - should generate -L,--locale locale
         addOption("L", "locale",         true,  "defaine the locale for this particular man search.").
         //FIXME - should generate -p,--preprocessor string
         addOption("p", "preprocessor",   true,  "string indicates which preprocessor to run.\n" +
                                                 " e - [n]eqn  p - pic     t - tbl\n" +
                                                 " g - grap    r - refer   v - vgrind").
         addOption("V", "version",        false, "show version.").
         addOption("h", "help",           false, "show this usage message.");

      HelpFormatter hf = new HelpFormatter();
      //hf.printHelp(cmdLine, opts);
      hf.printHelp(60, cmdLine, null, opts, null);
   }

   static void bzip2Example()
   {
      System.out.println( "Coming soon" );
   }

   static void lsExample()
   {
      System.out.println( "Coming soon" );
   }


   // -------------------------------------------------------------- Attributes

   // ------------------------------------------------------------ Constructors
   
   // ------------------------------------------------------------------ Public

   // --------------------------------------------------------------- Protected

   // ------------------------------------------------------- Package protected   
   
   // ----------------------------------------------------------------- Private
   
   // ----------------------------------------------------------- Inner classes

}