incubator-accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject svn commit: r1244690 - in /incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell: Shell.java commands/CreateTableCommand.java commands/DeleteRowsCommand.java commands/HelpCommand.java commands/MasterStateCommand.java
Date Wed, 15 Feb 2012 20:30:35 GMT
Author: billie
Date: Wed Feb 15 20:30:34 2012
New Revision: 1244690

URL: http://svn.apache.org/viewvc?rev=1244690&view=rev
Log:
ACCUMULO-333 added wrapping for shell command

Modified:
    incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
    incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
    incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java
    incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
    incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MasterStateCommand.java

Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java?rev=1244690&r1=1244689&r2=1244690&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
Wed Feb 15 20:30:34 2012
@@ -712,6 +712,10 @@ public class Shell {
       Shell.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp());
     }
     
+    public final void printHelp(int width) {
+      Shell.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp(),
width);
+    }
+    
     // Get options with help
     public final Options getOptionsWithHelp() {
       Options opts = getOptions();
@@ -960,8 +964,12 @@ public class Shell {
   }
   
   private static final void printHelp(String usage, String description, Options opts) {
+    printHelp(usage, description, opts, Integer.MAX_VALUE);
+  }
+  
+  private static final void printHelp(String usage, String description, Options opts, int
width) {
     PrintWriter pw = new PrintWriter(System.err);
-    new HelpFormatter().printHelp(pw, Integer.MAX_VALUE, usage, description, opts, 2, 5,
null, true);
+    new HelpFormatter().printHelp(pw, width, usage, description, opts, 2, 5, null, true);
     pw.flush();
   }
   
@@ -993,7 +1001,7 @@ public class Shell {
   public AuthInfo getCredentials() {
     return credentials;
   }
-
+  
   /**
    * Return the formatter for this table, .
    * 

Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java?rev=1244690&r1=1244689&r2=1244690&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java
Wed Feb 15 20:30:34 2012
@@ -181,7 +181,7 @@ public class CreateTableCommand extends 
     // Load custom formatter if set
     if (cl.hasOption(createTableOptFormatter.getOpt())) {
       String formatterClass = cl.getOptionValue(createTableOptFormatter.getOpt());
-
+      
       shellState.getConnector().tableOperations().setProperty(tableName, Property.TABLE_FORMATTER_CLASS.toString(),
formatterClass);
     }
     
@@ -216,7 +216,7 @@ public class CreateTableCommand extends 
     createTableOptCopyConfig.setArgName("table");
     createTableOptCopySplits.setArgName("table");
     createTableOptSplit.setArgName("filename");
-    createTableOptAgg.setArgName("{<columnfamily>[:<columnqualifier>]=<aggregation_class>}");
+    createTableOptAgg.setArgName("{<columnfamily>[:<columnqualifier>]=<aggregation
class>}");
     createTableOptFormatter.setArgName("className");
     
     // Splits and CopySplits are put in an optionsgroup to make them

Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java?rev=1244690&r1=1244689&r2=1244690&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java
Wed Feb 15 20:30:34 2012
@@ -54,7 +54,7 @@ public class DeleteRowsCommand extends C
   
   @Override
   public String description() {
-    return "delete a range of rows in a table\nNote that rows matching the start row ARE
NOT deleted, but rows matching the end row ARE deleted.";
+    return "delete a range of rows in a table.  Note that rows matching the start row ARE
NOT deleted, but rows matching the end row ARE deleted.";
   }
   
   @Override
@@ -77,4 +77,4 @@ public class DeleteRowsCommand extends C
     o.addOption(forceOpt);
     return o;
   }
-}
\ No newline at end of file
+}

Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java?rev=1244690&r1=1244689&r2=1244690&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
Wed Feb 15 20:30:34 2012
@@ -30,19 +30,52 @@ import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 
 public class HelpCommand extends Command {
-  
   private Option disablePaginationOpt;
+  private Option noWrapOpt;
   
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws ShellCommandException,
IOException {
+    int numColumns = shellState.getReader().getTermwidth();
+    if (cl.hasOption(noWrapOpt.getOpt()))
+      numColumns = Integer.MAX_VALUE;
+    
     // print help summary
     if (cl.getArgs().length == 0) {
       int i = 0;
       for (String cmd : shellState.commandFactory.keySet())
         i = Math.max(i, cmd.length());
+      if (numColumns < 40)
+        throw new IllegalArgumentException("numColumns must be at least 40 (was " + numColumns
+ ")");
       ArrayList<String> output = new ArrayList<String>();
       for (Command c : shellState.commandFactory.values()) {
-        if (!(c instanceof HiddenCommand))
-          output.add(String.format("%-" + i + "s  -  %s", c.getName(), c.description()));
+        if (!(c instanceof HiddenCommand)) {
+          String n = c.getName();
+          String s = c.description();
+          if (s == null)
+            s = "";
+          int beginIndex = 0;
+          int endIndex = s.length();
+          while (beginIndex < endIndex && s.charAt(beginIndex) == ' ')
+            beginIndex++;
+          String dash = "-";
+          while (endIndex > beginIndex && endIndex - beginIndex + i + 5 > numColumns)
{
+            endIndex = s.lastIndexOf(" ", numColumns + beginIndex - i - 5);
+            if (endIndex == -1 || endIndex < beginIndex) {
+              endIndex = numColumns + beginIndex - i - 5 - 1;
+              output.add(String.format("%-" + i + "s  %s  %s-", n, dash, s.substring(beginIndex,
endIndex)));
+              dash = " ";
+              beginIndex = endIndex;
+            } else {
+              output.add(String.format("%-" + i + "s  %s  %s", n, dash, s.substring(beginIndex,
endIndex)));
+              dash = " ";
+              beginIndex = endIndex + 1;
+            }
+            n = "";
+            endIndex = s.length();
+            while (beginIndex < endIndex && s.charAt(beginIndex) == ' ')
+              beginIndex++;
+          }
+          output.add(String.format("%-" + i + "s  %s  %s", n, dash, s.substring(beginIndex,
endIndex)));
+        }
       }
       shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()));
     }
@@ -53,7 +86,7 @@ public class HelpCommand extends Command
       if (c == null)
         shellState.getReader().printString(String.format("Unknown command \"%s\".  Enter
\"help\" for a list possible commands.\n", cmd));
       else
-        c.printHelp();
+        c.printHelp(numColumns);
     }
     return 0;
   }
@@ -71,6 +104,8 @@ public class HelpCommand extends Command
     Options o = new Options();
     disablePaginationOpt = new Option("np", "no-pagination", false, "disables pagination
of output");
     o.addOption(disablePaginationOpt);
+    noWrapOpt = new Option("nw", "no-wrap", false, "disables wrapping of output");
+    o.addOption(noWrapOpt);
     return o;
   }
   

Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MasterStateCommand.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MasterStateCommand.java?rev=1244690&r1=1244689&r2=1244690&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MasterStateCommand.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MasterStateCommand.java
Wed Feb 15 20:30:34 2012
@@ -36,7 +36,7 @@ public class MasterStateCommand extends 
   
   @Override
   public String usage() {
-    return "use the command line utility instead";
+    return "masterstate is deprecated, use the command line utility instead";
   }
   
   @Override



Mime
View raw message