Revision: 5563 http://jnode.svn.sourceforge.net/jnode/?rev=5563&view=rev Author: crawley Date: 2009-06-08 13:36:02 +0000 (Mon, 08 Jun 2009)
Log Message: ----------- Support completion of aliases in 'alias' and 'unalias' Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/bjorne/AliasBuiltin.java trunk/shell/src/shell/org/jnode/shell/bjorne/UnaliasBuiltin.java Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneAliasDefinitionArgument.java trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneAliasNameArgument.java Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/AliasBuiltin.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/AliasBuiltin.java 2009-06-08 10:07:38 UTC (rev 5562) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/AliasBuiltin.java 2009-06-08 13:36:02 UTC (rev 5563) @@ -27,7 +27,6 @@ import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ArgumentSyntax; import org.jnode.shell.syntax.RepeatSyntax; -import org.jnode.shell.syntax.StringArgument; import org.jnode.shell.syntax.SyntaxBundle; /** @@ -41,15 +40,16 @@ static final Factory FACTORY = new Factory() { public BjorneBuiltinCommandInfo buildCommandInfo(BjorneContext context) { - return new BjorneBuiltinCommandInfo("alias", SYNTAX, new AliasBuiltin(), context); + return new BjorneBuiltinCommandInfo("alias", SYNTAX, new AliasBuiltin(context), context); } }; - private final StringArgument argAlias = new StringArgument( - "alias", Argument.OPTIONAL + Argument.MULTIPLE, "an alias to be defined or printed"); + private final BjorneAliasDefinitionArgument argAlias; - private AliasBuiltin() { + private AliasBuiltin(BjorneContext context) { super("define or list aliases"); + argAlias = new BjorneAliasDefinitionArgument( + "alias", context, Argument.OPTIONAL + Argument.MULTIPLE, "an alias to be defined or printed"); registerArguments(argAlias); } Added: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneAliasDefinitionArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneAliasDefinitionArgument.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneAliasDefinitionArgument.java 2009-06-08 13:36:02 UTC (rev 5563) @@ -0,0 +1,70 @@ +/* + * $Id$ + * + * Copyright (C) 2003-2009 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.jnode.shell.bjorne; + +import org.jnode.driver.console.CompletionInfo; +import org.jnode.shell.CommandLine.Token; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.CommandSyntaxException; + +/** + * The BjorneAliasArgument understands 'arguments' of the form <name>['='[<alias body>]]. + * It will perform completion of the <name> component against the alias names + * defined in a supplied BjorneContext. + * + * @author craw...@jnode.org + */ +public class BjorneAliasDefinitionArgument extends Argument<String> { + private final BjorneContext context; + + public BjorneAliasDefinitionArgument(String label, BjorneContext context, int flags, String description) { + super(label, flags, new String[0], description); + this.context = context; + } + + @Override + protected String argumentKind() { + return "bjorne alias definition"; + } + + @Override + protected String doAccept(Token value, int flags) throws CommandSyntaxException { + String tok = value.text; + int pos = tok.indexOf('='); + String name = (pos == -1) ? tok : tok.substring(0, pos); + if (!BjorneToken.isName(name)) { + throw new CommandSyntaxException("invalid alias name ('" + name + "')"); + } + return tok; + } + + @Override + public void doComplete(CompletionInfo completions, String partial, int flags) { + int pos = partial.indexOf('='); + if (pos != -1) { + return; + } + for (String aliasName : context.getAliases().keySet()) { + if (aliasName.startsWith(partial)) { + completions.addCompletion(aliasName, true); + } + } + } +} Added: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneAliasNameArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneAliasNameArgument.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneAliasNameArgument.java 2009-06-08 13:36:02 UTC (rev 5563) @@ -0,0 +1,64 @@ +/* + * $Id$ + * + * Copyright (C) 2003-2009 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.jnode.shell.bjorne; + +import org.jnode.driver.console.CompletionInfo; +import org.jnode.shell.CommandLine.Token; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.CommandSyntaxException; + +/** + * The BjorneAliasNameArgument understands 'arguments' of the form <name>. + * It will perform completion of the <name> component against the alias names + * defined in a supplied BjorneContext. + * + * @author craw...@jnode.org + */ +public class BjorneAliasNameArgument extends Argument<String> { + private final BjorneContext context; + + public BjorneAliasNameArgument(String label, BjorneContext context, int flags, String description) { + super(label, flags, new String[0], description); + this.context = context; + } + + @Override + protected String argumentKind() { + return "bjorne alias name"; + } + + @Override + protected String doAccept(Token value, int flags) throws CommandSyntaxException { + String tok = value.text; + if (!BjorneToken.isName(tok)) { + throw new CommandSyntaxException("invalid name ('" + tok + "')"); + } + return tok; + } + + @Override + public void doComplete(CompletionInfo completions, String partial, int flags) { + for (String aliasName : context.getAliases().keySet()) { + if (aliasName.startsWith(partial)) { + completions.addCompletion(aliasName, true); + } + } + } +} Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/UnaliasBuiltin.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/UnaliasBuiltin.java 2009-06-08 10:07:38 UTC (rev 5562) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/UnaliasBuiltin.java 2009-06-08 13:36:02 UTC (rev 5563) @@ -27,7 +27,6 @@ import org.jnode.shell.syntax.FlagArgument; import org.jnode.shell.syntax.OptionSyntax; import org.jnode.shell.syntax.RepeatSyntax; -import org.jnode.shell.syntax.StringArgument; import org.jnode.shell.syntax.SyntaxBundle; /** @@ -42,18 +41,19 @@ static final Factory FACTORY = new Factory() { public BjorneBuiltinCommandInfo buildCommandInfo(BjorneContext context) { - return new BjorneBuiltinCommandInfo("unalias", SYNTAX, new UnaliasBuiltin(), context); + return new BjorneBuiltinCommandInfo("unalias", SYNTAX, new UnaliasBuiltin(context), context); } }; private final FlagArgument flagAll = new FlagArgument( "all", Argument.OPTIONAL, "if set, undefine all aliases"); - private final StringArgument argAlias = new StringArgument( - "alias", Argument.OPTIONAL + Argument.MULTIPLE, "aliases to be undefined"); + private final BjorneAliasNameArgument argAlias; - private UnaliasBuiltin() { + private UnaliasBuiltin(BjorneContext context) { super("undefined Bjorne shell aliases"); + argAlias = new BjorneAliasNameArgument( + "alias", context, Argument.OPTIONAL + Argument.MULTIPLE, "aliases to be undefined"); registerArguments(flagAll, argAlias); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get _______________________________________________ Jnode-svn-commits mailing list Jnode-svn-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits