You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/10/05 16:06:44 UTC
svn commit: r701798 - in /geronimo/gshell/trunk:
gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/
gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/
gshell-commands/gshell-vfs/sr...
Author: jdillon
Date: Sun Oct 5 07:06:43 2008
New Revision: 701798
URL: http://svn.apache.org/viewvc?rev=701798&view=rev
Log:
Expose ConsoleReader from IO
Added 'ls -l' support, ls will also handle FileType.FILE_OR_FOLDER now, dropped details on single file match
Modified:
geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearAction.java
geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java
geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.properties
geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java
geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java
Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearAction.java?rev=701798&r1=701797&r2=701798&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearAction.java (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/ClearAction.java Sun Oct 5 07:06:43 2008
@@ -25,8 +25,6 @@
import org.apache.geronimo.gshell.command.CommandContext;
import org.apache.geronimo.gshell.io.IO;
-import java.io.PrintWriter;
-
/**
* Clear the terminal screen.
*
@@ -46,16 +44,7 @@
return Result.FAILURE;
}
- //
- // FIXME: Need to have the framework provide a reader, which is initialized correctly?
- //
-
- ConsoleReader reader = new ConsoleReader(
- io.inputStream,
- new PrintWriter(io.outputStream, true),
- null, // bindings
- io.getTerminal());
-
+ ConsoleReader reader = io.createConsoleReader();
reader.clearScreen();
return Result.SUCCESS;
Modified: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java?rev=701798&r1=701797&r2=701798&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/java/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.java Sun Oct 5 07:06:43 2008
@@ -19,26 +19,21 @@
package org.apache.geronimo.gshell.commands.vfs;
-import org.apache.commons.vfs.FileContent;
+import jline.ConsoleReader;
+import org.apache.commons.vfs.FileFilter;
+import org.apache.commons.vfs.FileFilterSelector;
import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSelectInfo;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileType;
-import org.apache.commons.vfs.FileFilter;
-import org.apache.commons.vfs.FileSelectInfo;
-import org.apache.commons.vfs.FileFilterSelector;
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 java.text.DateFormat;
-import java.util.Date;
-import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
-import java.io.PrintWriter;
-
-import jline.ConsoleReader;
+import java.util.List;
/**
* List the contents of a file or directory.
@@ -51,15 +46,14 @@
@Argument
private String path;
- //
- // TODO: Add -l support
- //
+ @Option(name="-l", aliases={"--long"})
+ private boolean longList;
- @Option(name="-a")
- private boolean includeHidden = false;
+ @Option(name="-a", aliases={"--all"})
+ private boolean includeHidden;
@Option(name="-r", aliases={"--recursive"})
- private boolean recursive = false;
+ private boolean recursive;
public Object execute(final CommandContext context) throws Exception {
assert context != null;
@@ -73,18 +67,12 @@
file = getCurrentDirectory(context);
}
- if (file.getType() == FileType.FOLDER) {
+ FileType type = file.getType();
+ if (type == FileType.FOLDER || type == FileType.FILE_OR_FOLDER) {
listChildren(io, file);
}
else {
- io.info("{}", file.getName());
-
- FileContent content = file.getContent();
- io.verbose("Size: {} bytes", content.getSize());
-
- DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
- String lastMod = dateFormat.format(new Date(content.getLastModifiedTime()));
- io.verbose("Last modified: {}", lastMod);
+ io.info(file.getName().getPath());
}
closeFile(file);
@@ -117,17 +105,8 @@
files = dir.findFiles(new FileFilterSelector(filter));
}
-
- //
- // FIXME: Need to have the framework provide a reader, which is initialized correctly... or make this accessible via IO?
- //
-
- ConsoleReader reader = new ConsoleReader(
- io.inputStream,
- new PrintWriter(io.outputStream, true),
- null, // bindings
- io.getTerminal());
+ ConsoleReader reader = io.createConsoleReader();
reader.setUsePagination(false);
List<String> names = new ArrayList<String>(files.length);
@@ -140,7 +119,7 @@
names.add(file.getName().getBaseName());
}
- else if (type == FileType.FOLDER) {
+ else if (type == FileType.FOLDER || type == FileType.FILE_OR_FOLDER) {
names.add(file.getName().getBaseName() + "/");
if (recursive) {
@@ -152,8 +131,15 @@
}
}
- reader.printColumns(names);
-
+ if (longList) {
+ for (String name : names) {
+ io.out.println(name);
+ }
+ }
+ else {
+ reader.printColumns(names);
+ }
+
if (!dirs.isEmpty()) {
for (FileObject subdir : dirs) {
io.out.println();
Modified: geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.properties
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.properties?rev=701798&r1=701797&r2=701798&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.properties (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-vfs/src/main/resources/org/apache/geronimo/gshell/commands/vfs/ListDirectoryAction.properties Sun Oct 5 07:06:43 2008
@@ -28,6 +28,8 @@
command.argument.path=The file or directory path to list.
command.argument.path.token=PATH
+command.option.longList=List in long format
+
command.option.includeHidden=Include hidden files
command.option.recursive=List the contents of directories recursivly
Modified: geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java?rev=701798&r1=701797&r2=701798&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-io/src/main/java/org/apache/geronimo/gshell/io/IO.java Sun Oct 5 07:06:43 2008
@@ -20,6 +20,7 @@
package org.apache.geronimo.gshell.io;
import jline.Terminal;
+import jline.ConsoleReader;
import org.apache.geronimo.gshell.ansi.RenderWriter;
import org.apache.geronimo.gshell.yarn.Yarn;
import org.codehaus.plexus.util.IOUtil;
@@ -346,4 +347,16 @@
public void error(final String format, final Object... args) {
err.println(MessageFormatter.arrayFormat(format, args));
}
+
+ //
+ // HACK: Expose creation of a configured ConsoleReader, really need to rethink this class soon.
+ //
+
+ public ConsoleReader createConsoleReader() throws IOException {
+ return new ConsoleReader(
+ inputStream,
+ new PrintWriter(outputStream, true),
+ null, // bindings
+ getTerminal());
+ }
}
Modified: geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java?rev=701798&r1=701797&r2=701798&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java (original)
+++ geronimo/gshell/trunk/gshell-support/gshell-vfs/src/main/java/org/apache/geronimo/gshell/vfs/FileSystemAccessImpl.java Sun Oct 5 07:06:43 2008
@@ -118,7 +118,7 @@
return getManager().resolveFile(baseFile, name);
}
- public FileObject resolveFile(String name) throws FileSystemException {
+ public FileObject resolveFile(final String name) throws FileSystemException {
return getManager().resolveFile(getCurrentDirectory(), name);
}
}
\ No newline at end of file