|
From: <cr...@us...> - 2008-05-03 06:24:28
|
Revision: 4042
http://jnode.svn.sourceforge.net/jnode/?rev=4042&view=rev
Author: crawley
Date: 2008-05-02 23:24:24 -0700 (Fri, 02 May 2008)
Log Message:
-----------
Converted 'cat' command
Modified Paths:
--------------
trunk/fs/descriptors/org.jnode.fs.command.xml
trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java
Modified: trunk/fs/descriptors/org.jnode.fs.command.xml
===================================================================
--- trunk/fs/descriptors/org.jnode.fs.command.xml 2008-05-03 02:39:44 UTC (rev 4041)
+++ trunk/fs/descriptors/org.jnode.fs.command.xml 2008-05-03 06:24:24 UTC (rev 4042)
@@ -36,6 +36,18 @@
</extension>
<extension point="org.jnode.shell.syntaxes">
+ <syntax alias="cat">
+ <empty description="copy standard input to standard output"/>
+ <sequence description="concatenate urls to standard output">
+ <option argLabel="urls" shortName="u" longName="urls"/>
+ <repeat minCount="1">
+ <argument argLabel="url"/>
+ </repeat>
+ </sequence>
+ <repeat minCount="1" description="concatenate files to standard output">
+ <argument argLabel="file"/>
+ </repeat>
+ </syntax>
<syntax alias="del">
<sequence description="delete a file or directory">
<optionSet>
Modified: trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2008-05-03 02:39:44 UTC (rev 4041)
+++ trunk/fs/src/fs/org/jnode/fs/command/CatCommand.java 2008-05-03 06:24:24 UTC (rev 4042)
@@ -32,12 +32,7 @@
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.argument.FileArgument;
-import org.jnode.shell.help.argument.URLArgument;
+import org.jnode.shell.syntax.*;
/**
* @author epr
@@ -47,28 +42,23 @@
*/
public class CatCommand extends AbstractCommand {
- static final FileArgument ARG_FILE = new FileArgument("file",
- "the files to be concatenated", true);
+ private final FileArgument ARG_FILE =
+ new FileArgument("file", Argument.OPTIONAL | Argument.MULTIPLE,
+ "the files to be concatenated");
- static final URLArgument ARG_URL = new URLArgument("url",
- "the files to be concatenated", true);
+ private final URLArgument ARG_URL =
+ new URLArgument("url", Argument.OPTIONAL | Argument.MULTIPLE,
+ "the urls to be concatenated");
- public static Help.Info HELP_INFO = new Help.Info("cat",
- new Syntax[] {
- new Syntax(
- "Fetch the argument urls and copy their contents to standard output.",
- new Parameter[] {
- new Parameter("u",
- "selects urls rather than pathnames",
- ARG_URL, Parameter.MANDATORY)}),
- new Syntax(
- "Read the argument files, copying their contents to standard output. " +
- "If there are no arguments, standard input is read until EOF is reached; " +
- "e.g. ^D when reading keyboard input.",
- new Parameter[] {
- new Parameter(ARG_FILE, Parameter.OPTIONAL) })
-
- });
+ private final FlagArgument FLAG_URLS =
+ new FlagArgument("urls", Argument.OPTIONAL, "If set, arguments will be urls");
+
+ public CatCommand() {
+ super("Read the argument files or urls, copying their contents to standard output. " +
+ "If there are no arguments, standard input is read until EOF is reached; " +
+ "e.g. ^D when reading keyboard input.");
+ registerArguments(ARG_FILE, ARG_URL, FLAG_URLS);
+ }
private static final int BUFFER_SIZE = 1024;
@@ -77,10 +67,10 @@
new CatCommand().execute(args);
}
- public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- ParsedArguments args = HELP_INFO.parse(commandLine);
- File[] files = ARG_FILE.getFiles(args);
- String[] urls = ARG_URL.getValues(args);
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err)
+ throws Exception {
+ File[] files = ARG_FILE.getValues();
+ String[] urls = ARG_URL.getValues();
boolean ok = true;
try {
if (urls != null && urls.length > 0) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|