geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r632233 - in /geronimo/gshell/trunk: gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
Date Fri, 29 Feb 2008 06:39:23 GMT
Author: jdillon
Date: Thu Feb 28 22:39:23 2008
New Revision: 632233

URL: http://svn.apache.org/viewvc?rev=632233&view=rev
Log:
(GSHELL-66) Auto-generate cli syntax/usage string when displaying --help (patch from J Warner,
thx)

Modified:
    geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
    geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java

Modified: geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java?rev=632233&r1=632232&r2=632233&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
(original)
+++ geronimo/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/CommandSupport.java
Thu Feb 28 22:39:23 2008
@@ -116,13 +116,9 @@
         //
         // FIXME: This is uuuuuggggllyyyy
         //
-        
-        io.out.println(name);
-        io.out.println(" -- ");
-        io.out.println();
 
         Printer printer = new Printer(clp);
-        printer.printUsage(io.out);
+        printer.printUsage(io.out, name);
         io.out.println();
     }
 }

Modified: geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java?rev=632233&r1=632232&r2=632233&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
(original)
+++ geronimo/gshell/trunk/gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/Printer.java
Thu Feb 28 22:39:23 2008
@@ -93,7 +93,7 @@
         return getNameAndMeta(handler, bundle).length();
     }
 
-    public void printUsage(final Writer writer, final ResourceBundle bundle) {
+    public void printUsage(final Writer writer, final ResourceBundle bundle, final String
name) {
         assert writer != null;
 
         PrintWriter out = new PrintWriter(writer);
@@ -110,9 +110,22 @@
                 return a.descriptor.toString().compareTo(b.descriptor.toString());
             }
         });
+        
+        if (name != null) {
+        	String syntax = "syntax: " + name;
+        	if (!optionHandlers.isEmpty()) {
+        		syntax += " [options]";
+        	}
+        	if (!argumentHandlers.isEmpty()) {
+        		syntax += " [arguments]";
+        	}
+        	out.println(syntax);
+        	out.println();
+        }
 
         // Compute the maximum length of the syntax column
         int len = 0;
+        
 
         for (Handler handler : optionHandlers) {
             int curLen = getPrefixLen(handler, bundle);
@@ -125,10 +138,17 @@
         }
 
         // And then render the handler usage
+        if (!argumentHandlers.isEmpty()) {
+        	out.println("arguments:");
+        }
         for (Handler handler : argumentHandlers) {
             printHandler(out, handler, len, bundle);
         }
 
+        if (!optionHandlers.isEmpty()) {
+        	out.println();
+        	out.println("options:");
+        }
         for (Handler handler : optionHandlers) {
             printHandler(out, handler, len, bundle);
         }
@@ -137,7 +157,11 @@
     }
 
     public void printUsage(final Writer writer) {
-        printUsage(writer, null);
+        printUsage(writer, null, null);
+    }
+    
+    public void printUsage(final Writer writer, final String name) {
+    	printUsage(writer, null, name);
     }
 
     private void printHandler(final PrintWriter out, final Handler handler, final int len,
final ResourceBundle bundle) {



Mime
View raw message