From: <cr...@us...> - 2008-04-14 13:47:56
|
Revision: 3955 http://jnode.svn.sourceforge.net/jnode/?rev=3955&view=rev Author: crawley Date: 2008-04-14 06:47:55 -0700 (Mon, 14 Apr 2008) Log Message: ----------- Converted 'echo' command to new syntax Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-14 13:47:05 UTC (rev 3954) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-04-14 13:47:55 UTC (rev 3955) @@ -88,6 +88,11 @@ </repeat> </sequence> </syntax> + <syntax alias="echo"> + <repeat> + <argument argLabel="text"/> + </repeat> + </syntax> <syntax alias="set"> <sequence description="set a system property"> <argument argLabel="key"/> Modified: trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-04-14 13:47:05 UTC (rev 3954) +++ trunk/shell/src/shell/org/jnode/shell/command/EchoCommand.java 2008-04-14 13:47:55 UTC (rev 3955) @@ -23,47 +23,45 @@ import java.io.InputStream; import java.io.PrintStream; -import java.util.Iterator; import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.Argument; -import org.jnode.shell.help.Help; -import org.jnode.shell.help.Parameter; -import org.jnode.shell.help.argument.StringArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.StringArgument; /** + * Echo the command's arguments to its output. + * * @author epr + * @author cr...@jn... */ - public class EchoCommand extends AbstractCommand { - - public static Help.Info HELP_INFO = new Help.Info( - "echo", "Print the given text", - new Parameter[]{ - new Parameter(new StringArgument("arg", "the text to print", Argument.MULTI), Parameter.OPTIONAL) - } - ); - + + private final StringArgument ARG_WORDS = + new StringArgument("text", Argument.MULTIPLE, "the text to be printed"); + + public EchoCommand() { + super("Print the argument text to standard output"); + registerArguments(ARG_WORDS); + } + public static void main(String[] args) throws Exception { new EchoCommand().execute(args); } /** - * Execute this command + * Execute the command */ @SuppressWarnings("deprecation") - public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) + public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - Iterator<String> it = commandLine.iterator(); - int i = 0; - while (it.hasNext()) { - if (i > 0) { - out.print(' '); - } - out.print(it.next()); - i++; - } - out.println(); + String[] words = ARG_WORDS.getValues(); + for (int i = 0; i < words.length; i++) { + if (i > 0) { + out.print(' '); + } + out.print(words[i]); + } + out.println(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |