geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r700009 - in /geronimo/gshell/trunk/gshell-commands: gshell-optional/src/main/java/org/apache/geronimo/gshell/commands/optional/ gshell-optional/src/main/resources/META-INF/spring/ gshell-optional/src/main/resources/org/apache/geronimo/gshe...
Date Mon, 29 Sep 2008 07:35:22 GMT
Author: jdillon
Date: Mon Sep 29 00:35:22 2008
New Revision: 700009

URL: http://svn.apache.org/viewvc?rev=700009&view=rev
Log:
Drop 'cat' action in gshell-optional, make 'cat' in gshell-vfs behave more like it did in
gshell-optional, sill need to support '-' and multi paths

Removed:
    geronimo/gshell/trunk/gshell-commands/gshell-optional/src/main/java/org/apache/geronimo/gshell/commands/optional/CatAction.java
    geronimo/gshell/trunk/gshell-commands/gshell-optional/src/main/resources/org/apache/geronimo/gshell/commands/optional/CatAction.properties
Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-optional/src/main/resources/META-INF/spring/components.xml
    geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/CatAction.java
    geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/CatAction.properties

Modified: geronimo/gshell/trunk/gshell-commands/gshell-optional/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-optional/src/main/resources/META-INF/spring/components.xml?rev=700009&r1=700008&r2=700009&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-optional/src/main/resources/META-INF/spring/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-optional/src/main/resources/META-INF/spring/components.xml
Mon Sep 29 00:35:22 2008
@@ -29,10 +29,6 @@
 
     <gshell:plugin name="gshell-optional">
         <gshell:command-bundle name="default">
-            <gshell:command name="cat">
-                <gshell:action class="org.apache.geronimo.gshell.commands.optional.CatAction"/>
-            </gshell:command>
-
             <gshell:command name="exec">
                 <gshell:action class="org.apache.geronimo.gshell.commands.optional.ExecuteAction"/>
             </gshell:command>

Modified: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/CatAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/CatAction.java?rev=700009&r1=700008&r2=700009&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/CatAction.java
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/CatAction.java
Mon Sep 29 00:35:22 2008
@@ -19,12 +19,20 @@
 
 package org.apache.geronimo.gshell.commands.vfs;
 
+import org.apache.commons.vfs.FileContent;
+import org.apache.commons.vfs.FileContentInfo;
 import org.apache.commons.vfs.FileObject;
-import org.apache.commons.vfs.FileUtil;
 import org.apache.commons.vfs.FileType;
 import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.clp.Option;
 import org.apache.geronimo.gshell.command.CommandContext;
 import org.apache.geronimo.gshell.io.IO;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 
 /**
  * Displays the contents of a file.
@@ -37,10 +45,17 @@
     @Argument(required=true)
     private String path;
 
+    @Option(name="-n")
+    private boolean displayLineNumbers;
+
     public Object execute(final CommandContext context) throws Exception {
         assert context != null;
         IO io = context.getIo();
 
+        //
+        // TODO: Support multi-path cat, and the special '-' token (which is the default
if no paths are given)
+        //
+
         FileObject file = resolveFile(context, path);
 
         if (!file.exists()) {
@@ -51,10 +66,42 @@
             io.error("File is a directory: {}", file.getName());
             return Result.FAILURE;
         }
-        
-        FileUtil.writeContent(file, io.outputStream);
+
+        FileContent content = file.getContent();
+        FileContentInfo info = content.getContentInfo();
+        log.debug("Content type: {}", info.getContentType());
+        log.debug("Content encoding: {}", info.getContentEncoding());
+
+        //
+        // TODO: Only cat files which we think are text
+        //
+
+        log.debug("Displaying file: {}", file.getName());
+
+        BufferedReader reader = new BufferedReader(new InputStreamReader(content.getInputStream()));
+        try {
+            cat(reader, io);
+        }
+        finally {
+            IOUtil.close(reader);
+        }
+
         io.out.println();
 
         return Result.SUCCESS;
     }
+
+    private void cat(final BufferedReader reader, final IO io) throws IOException {
+        String line;
+        int lineno = 1;
+
+        while ((line = reader.readLine()) != null) {
+            if (displayLineNumbers) {
+                String gutter = StringUtils.leftPad(String.valueOf(lineno++), 6);
+                io.out.print(gutter);
+                io.out.print("  ");
+            }
+            io.out.println(line);
+        }
+    }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/CatAction.properties
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/CatAction.properties?rev=700009&r1=700008&r2=700009&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/CatAction.properties
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/CatAction.properties
Mon Sep 29 00:35:22 2008
@@ -28,5 +28,7 @@
 command.argument.path=Path to file to display
 command.argument.path.token=PATH
 
+command.option.displayLineNumbers=Number the output lines, starting at 1
+
 command.manual=\
   TODO: cat manual
\ No newline at end of file



Mime
View raw message