From: <cr...@us...> - 2008-03-27 12:06:59
|
Revision: 3889 http://jnode.svn.sourceforge.net/jnode/?rev=3889&view=rev Author: crawley Date: 2008-03-27 05:06:55 -0700 (Thu, 27 Mar 2008) Log Message: ----------- Converted 'alias' command to use new syntax system Modified Paths: -------------- trunk/shell/descriptors/org.jnode.shell.command.xml trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java Modified: trunk/shell/descriptors/org.jnode.shell.command.xml =================================================================== --- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-03-27 12:05:55 UTC (rev 3888) +++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-03-27 12:06:55 UTC (rev 3889) @@ -49,11 +49,20 @@ <extension point="org.jnode.shell.syntaxes"> <syntax alias="set"> - <sequence> + <sequence description="set a system property"> <argument argLabel="key"/> <argument argLabel="value"/> </sequence> + <argument description="remove a system property" argLabel="key"/> </syntax> + <syntax alias="alias"> + <empty description="list all aliases"/> + <option argLabel="remove" shortName="r" description="remove an alias"/> + <sequence description="create or update an alias"> + <argument argLabel="alias"/> + <argument argLabel="classname"/> + </sequence> + </syntax> </extension> <extension point="org.jnode.security.permissions"> Modified: trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-03-27 12:05:55 UTC (rev 3888) +++ trunk/shell/src/shell/org/jnode/shell/command/AliasCommand.java 2008-03-27 12:06:55 UTC (rev 3889) @@ -28,48 +28,34 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.Shell; import org.jnode.shell.ShellUtils; import org.jnode.shell.alias.AliasManager; import org.jnode.shell.alias.NoSuchAliasException; -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.AliasArgument; -import org.jnode.shell.help.argument.ClassNameArgument; +import org.jnode.shell.syntax.AliasArgument; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.ClassNameArgument; /** * @author epr * @author qades * @author Martin Husted Hartvig (ha...@jn...) + * @author cr...@jn... */ public class AliasCommand extends AbstractCommand { - static final AliasArgument ARG_ALIAS = new AliasArgument("alias", - "the alias"); - - static final ClassNameArgument ARG_CLASS = new ClassNameArgument( - "classname", "the classname"); - - static final Parameter PARAM_REMOVE = new Parameter("r", - "following alias will be removed", ARG_ALIAS, Parameter.MANDATORY); - private final static String slash_t = ":\t\t"; - public static Help.Info HELP_INFO = new Help.Info( - "alias", - new Syntax[] { - new Syntax( - "Print all available aliases and corresponding classnames"), - new Syntax("Set an aliases for given classnames", - new Parameter[] { - new Parameter(ARG_ALIAS, - Parameter.MANDATORY), - new Parameter(ARG_CLASS, - Parameter.MANDATORY) }), - new Syntax("Remove an alias", - new Parameter[] { PARAM_REMOVE }) }); + private final AliasArgument ARG_ALIAS; + private final ClassNameArgument ARG_CLASS; + private final AliasArgument ARG_REMOVE; + + public AliasCommand() { + super("list, add or remove JNode command aliases"); + ARG_ALIAS = new AliasArgument("alias", Argument.OPTIONAL, "the alias to be added"); + ARG_CLASS = new ClassNameArgument("classname", Argument.OPTIONAL, "the classname"); + ARG_REMOVE = new AliasArgument("remove", Argument.OPTIONAL, "the alias to be removed"); + registerArguments(ARG_ALIAS, ARG_CLASS, ARG_REMOVE); + } public static void main(String[] args) throws Exception { new AliasCommand().execute(args); @@ -90,20 +76,17 @@ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception { - ParsedArguments parsedArguments = HELP_INFO.parse(commandLine); + final AliasManager aliasMgr = ShellUtils.getCurrentAliasManager(); - final Shell shell = ShellUtils.getShellManager().getCurrentShell(); - final AliasManager aliasMgr = shell.getAliasManager(); - - if (parsedArguments.size() == 0) { - showAliases(aliasMgr, out); - } else if (PARAM_REMOVE.isSet(parsedArguments)) { + if (ARG_REMOVE.isSet()) { // remove an alias - aliasMgr.remove(ARG_ALIAS.getValue(parsedArguments)); - } else { + aliasMgr.remove(ARG_REMOVE.getValue()); + } else if (ARG_ALIAS.isSet()) { // add an alias - aliasMgr.add(ARG_ALIAS.getValue(parsedArguments), ARG_CLASS - .getValue(parsedArguments)); - } + aliasMgr.add(ARG_ALIAS.getValue(), ARG_CLASS.getValue()); + } else { + // list the aliases + showAliases(aliasMgr, out); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |