|
From: <cr...@us...> - 2009-04-12 01:05:09
|
Revision: 5249
http://jnode.svn.sourceforge.net/jnode/?rev=5249&view=rev
Author: crawley
Date: 2009-04-12 01:05:05 +0000 (Sun, 12 Apr 2009)
Log Message:
-----------
Commit of patch from issue #2959. Adds ability to contextually set (some)
Argument 'flags' from a syntax. Defines two new flags for FileArgument.
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSHostNameArgument.java
trunk/fs/src/fs/org/jnode/partitions/command/IBMPartitionTypeArgument.java
trunk/net/src/net/org/jnode/net/syntax/IPv4AddressArgument.java
trunk/net/src/net/org/jnode/net/syntax/IPv4HostArgument.java
trunk/shell/src/shell/org/jnode/shell/ArgumentCompleter.java
trunk/shell/src/shell/org/jnode/shell/CommandLine.java
trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java
trunk/shell/src/shell/org/jnode/shell/syntax/AliasArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/Argument.java
trunk/shell/src/shell/org/jnode/shell/syntax/ArgumentBundle.java
trunk/shell/src/shell/org/jnode/shell/syntax/ArgumentSyntax.java
trunk/shell/src/shell/org/jnode/shell/syntax/ClassNameArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/CountryArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/DeviceArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/EnumArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/FileArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/FlagArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/HostNameArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/IntegerArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/KeyboardLayoutArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/LanguageArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLoggerArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/LongArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/MappedArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/MuArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/MuParser.java
trunk/shell/src/shell/org/jnode/shell/syntax/MuPreset.java
trunk/shell/src/shell/org/jnode/shell/syntax/OptionSetSyntax.java
trunk/shell/src/shell/org/jnode/shell/syntax/OptionSyntax.java
trunk/shell/src/shell/org/jnode/shell/syntax/PluginArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/PropertyNameArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/SizeArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/StringArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/SyntaxSpecLoader.java
trunk/shell/src/shell/org/jnode/shell/syntax/ThreadNameArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/URLArgument.java
trunk/shell/src/shell/org/jnode/shell/syntax/VerbSyntax.java
trunk/shell/src/test/org/jnode/test/shell/CompletionTest.java
trunk/shell/src/test/org/jnode/test/shell/syntax/MuSyntaxTest.java
Modified: trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSHostNameArgument.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSHostNameArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/fs/src/fs/org/jnode/fs/nfs/command/NFSHostNameArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -43,7 +43,7 @@
super(name, flags, new String[0], description);
}
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
int index = partial.indexOf(':');
if (index <= 0) {
return;
@@ -117,7 +117,7 @@
}
@Override
- protected String doAccept(Token value) throws CommandSyntaxException {
+ protected String doAccept(Token value, int flags) throws CommandSyntaxException {
int index = value.text.indexOf(':');
if (index == -1) {
throw new CommandSyntaxException("missing ':'");
Modified: trunk/fs/src/fs/org/jnode/partitions/command/IBMPartitionTypeArgument.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/command/IBMPartitionTypeArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/fs/src/fs/org/jnode/partitions/command/IBMPartitionTypeArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -38,7 +38,7 @@
}
@Override
- protected IBMPartitionTypes doAccept(Token value) throws CommandSyntaxException {
+ protected IBMPartitionTypes doAccept(Token value, int flags) throws CommandSyntaxException {
try {
int code = Integer.parseInt(value.text, 16);
return IBMPartitionTypes.valueOf(code);
@@ -50,7 +50,7 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
partial = partial.toLowerCase();
for (IBMPartitionTypes pt : IBMPartitionTypes.values()) {
String code = Integer.toHexString(pt.getCode());
Modified: trunk/net/src/net/org/jnode/net/syntax/IPv4AddressArgument.java
===================================================================
--- trunk/net/src/net/org/jnode/net/syntax/IPv4AddressArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/net/src/net/org/jnode/net/syntax/IPv4AddressArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -45,7 +45,7 @@
}
@Override
- protected IPv4Address doAccept(Token value) throws CommandSyntaxException {
+ protected IPv4Address doAccept(Token value, int flags) throws CommandSyntaxException {
if (value.text.equals("default")) {
return new IPv4Address(new byte[]{0, 0, 0, 0}, 0);
}
Modified: trunk/net/src/net/org/jnode/net/syntax/IPv4HostArgument.java
===================================================================
--- trunk/net/src/net/org/jnode/net/syntax/IPv4HostArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/net/src/net/org/jnode/net/syntax/IPv4HostArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -43,7 +43,7 @@
}
@Override
- protected IPv4Address doAccept(Token value) throws CommandSyntaxException {
+ protected IPv4Address doAccept(Token value, int flags) throws CommandSyntaxException {
try {
return new IPv4Address(value.text);
} catch (IllegalArgumentException ex) {
Modified: trunk/shell/src/shell/org/jnode/shell/ArgumentCompleter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/ArgumentCompleter.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/ArgumentCompleter.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -46,7 +46,7 @@
}
public void complete(CompletionInfo completion, CommandShell shell) {
- argument.complete(completion, token == null ? "" : token.text);
+ argument.complete(completion, token == null ? "" : token.text, 0);
if (token != null) {
completion.setCompletionStart(token.start);
}
Modified: trunk/shell/src/shell/org/jnode/shell/CommandLine.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/CommandLine.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -643,7 +643,7 @@
// We haven't got a command name yet, so complete the partial command name string
// as an AliasArgument.
AliasArgument cmdNameArg = new AliasArgument("cmdName", Argument.SINGLE);
- cmdNameArg.complete(completion, cmd);
+ cmdNameArg.complete(completion, cmd, 0);
completion.setCompletionStart(commandToken == null ? 0 : commandToken.start);
}
}
Modified: trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -125,7 +125,7 @@
}
@Override
- protected VirtualKey doAccept(Token value) throws CommandSyntaxException {
+ protected VirtualKey doAccept(Token value, int flags) throws CommandSyntaxException {
String str = value.text;
String[] parts = str.split("\\+");
int modifiers = 0;
@@ -156,7 +156,7 @@
}
@Override
- protected Character doAccept(Token value) throws CommandSyntaxException {
+ protected Character doAccept(Token value, int flags) throws CommandSyntaxException {
String str = value.text;
String upper = str.toUpperCase();
for (int i = 0; i < ASCII_NAMES.length; i++) {
Modified: trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/command/test/SuiteCommand.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -97,7 +97,7 @@
super(label, flags, description);
}
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
Set<String> availCategories = TestManager.getInstance().getCategories();
for (String availCategory : availCategories) {
if (availCategory.startsWith(partial)) {
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/AliasArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/AliasArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/AliasArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -49,14 +49,14 @@
}
@Override
- public String doAccept(Token value) throws CommandSyntaxException {
+ public String doAccept(Token value, int flags) throws CommandSyntaxException {
if (value.text.length() == 0) {
throw new CommandSyntaxException("empty alias name");
}
return value.text;
}
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
try {
// get the alias manager
final AliasManager aliasMgr =
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/Argument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/Argument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/Argument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -55,44 +55,70 @@
public abstract class Argument<V> {
/**
- * This Argument flag indicates that the Argument is optional.
+ * This Argument flag indicates that the Argument is optional. This is the
+ * opposite of MANDATORY, and is the default if neither are specified.
*/
public static final int OPTIONAL = 0x001;
/**
- * This Argument flag indicates that the Argument is mandatory. At least
- * one instance of this Argument must be supplied.
+ * This Argument flag indicates that the Argument is mandatory; i.e that least
+ * one instance of this Argument must be supplied in a command line. This is
+ * the opposite of OPTIONAL.
*/
public static final int MANDATORY = 0x002;
/**
* This Argument flag indicates that the Argument may have at most one value.
+ * This is the opposite of MULTIPLE and the default if neither are specified.
*/
public static final int SINGLE = 0x004;
/**
* This Argument flag indicates that multiple instances of this Argument may
- * be provided.
+ * be provided. This is the opposite of SINGLE.
*/
public static final int MULTIPLE = 0x008;
/**
* This Argument flag indicates that an Argument's value must denote an entity
* that already exists in whatever domain that the Argument values corresponds to.
+ * Note that this is <b>not</b> the logical negation of NONEXISTENT!
*/
public static final int EXISTING = 0x010;
/**
* This Argument flag indicates that an Argument's value must denote an entity
* that does not exists in whatever domain that the Argument values corresponds to.
+ * Note that this is <b>not</b> the logical negation of EXISTING!
*/
public static final int NONEXISTENT = 0x020;
+
+ /**
+ * Flag bits in this bitset are either common flags, or reserved for future use as
+ * common flags.
+ */
+ public static final int COMMON_FLAGS = 0x0000ffff;
+ /**
+ * Flag bits in this bitset are available for use as Argument-subclass specific flags.
+ * Flags in this range may be overridden by a Syntax.
+ */
+ public static final int SPECIFIC_OVERRIDABLE_FLAGS = 0x00ff0000;
+
+ /**
+ * Flag bits in this bitset are available for use as Argument-subclass specific flags.
+ * Flags in this range may NOT be overridden by a Syntax.
+ */
+ private static final int SPECIFIC_NONOVERRIDABLE_FLAGS = 0xff000000;
+
+ /**
+ * Flag bits in this bitset may not be overridden by a Syntax.
+ */
+ public static final int NONOVERRIDABLE_FLAGS =
+ SINGLE | MULTIPLE | MANDATORY | OPTIONAL | SPECIFIC_NONOVERRIDABLE_FLAGS;
+
private final String label;
- private final boolean mandatory;
- private final boolean multiple;
- private final boolean existing;
- private final boolean nonexistent;
+ private final int flags;
private final String description;
protected final List<V> values = new ArrayList<V>();
@@ -114,6 +140,22 @@
protected Argument(String label, int flags, V[] vArray, String description)
throws IllegalArgumentException {
super();
+ checkFlags(flags);
+ this.label = label;
+ this.description = description;
+ this.flags = flags;
+ this.vArray = vArray;
+ }
+
+ /**
+ * Check that the supplied flags are consistent.
+ * <p>
+ * Note: this method may be overridden in child classes, but an override should
+ * call this method to check the common flags.
+ * @param flags the flags to be checked.
+ * @throws IllegalArgumentException
+ */
+ protected void checkFlags(int flags) throws IllegalArgumentException {
if ((flags & EXISTING) != 0 && (flags & NONEXISTENT) != 0) {
throw new IllegalArgumentException("inconsistent flags: EXISTING and NONEXISTENT");
}
@@ -123,33 +165,162 @@
if ((flags & MANDATORY) != 0 && (flags & OPTIONAL) != 0) {
throw new IllegalArgumentException("inconsistent flags: MANDATORY and OPTIONAL");
}
- this.label = label;
- this.description = description;
- this.mandatory = (flags & MANDATORY) != 0;
- this.multiple = (flags & MULTIPLE) != 0;
- this.existing = (flags & EXISTING) != 0;
- this.nonexistent = (flags & NONEXISTENT) != 0;
- this.vArray = vArray;
}
/**
- * Reconstruct and return Argument flags equiivalent to those passed to the constructor.
+ * Return the flags as passed to the constructor.
* @return the flags.
*/
public int getFlags() {
- return ((mandatory ? MANDATORY : OPTIONAL) | (multiple ? MULTIPLE : SINGLE) |
- (existing ? EXISTING : 0) | (nonexistent ? NONEXISTENT : 0));
+ return flags;
}
+
+ /**
+ * Convert a comma-separated list of names to a flags word. The current implementation
+ * will silently ignore empty names; e.g. in {@code "MANDATORY,,SINGLE"} or
+ * {@code ",SINGLE"}.
+ *
+ * @param names the names separated by commas and optional whitespace.
+ * @return the flags
+ * @throws IllegalArgument if the list contains unknown flag names.
+ */
+ public final int namesToFlags(String names) throws IllegalArgumentException {
+ String[] nameList = names.trim().split("\\s*,\\s*");
+ int res = 0;
+ for (String name : nameList) {
+ if (name != null && name.length() > 0) {
+ res |= nameToFlag(name);
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Convert a flag name to a flag.
+ * <p>
+ * Note: this method may be overridden in child
+ * classes, but an override should end by calling this method to deal
+ * with flag names that it doesn't understand.
+ *
+ * @param name the name to be converted
+ * @return the corresponding flag
+ * @throws IllegalArgumentWxception if the name is not recognized
+ */
+ public int nameToFlag(String name) throws IllegalArgumentException {
+ if (name.equals("MANDATORY")) {
+ return MANDATORY;
+ } else if (name.equals("OPTIONAL")) {
+ return OPTIONAL;
+ } else if (name.equals("SINGLE")) {
+ return SINGLE;
+ } else if (name.equals("MULTIPLE")) {
+ return MULTIPLE;
+ } else if (name.equals("EXISTING")) {
+ return EXISTING;
+ } else if (name.equals("NONEXISTENT")) {
+ return NONEXISTENT;
+ } else {
+ throw new IllegalArgumentException("unknown flag name '" + name + "'");
+ }
+ }
/**
* If this method returns <code>true</code>, this Argument must be bound to an
* argument in a CommandLine if it is used in a given concrete syntax.
*/
public boolean isMandatory() {
- return mandatory;
+ return isMandatory(flags);
}
/**
+ * If this method returns <code>true</code>, this Argument need not be bound to an
+ * argument in a CommandLine if it is used in a given concrete syntax.
+ */
+ public boolean isOptional() {
+ return isOptional(flags);
+ }
+
+ /**
+ * If this method returns <code>true</code>, this element may have
+ * multiple instances in a CommandLine.
+ */
+ public boolean isMultiple() {
+ return isMultiple(flags);
+ }
+
+ /**
+ * If this method returns <code>true</code>, this element must have at
+ * most one instance in a CommandLine.
+ */
+ public boolean isSingle() {
+ return isSingle(flags);
+ }
+
+ /**
+ * If this method returns <code>true</code>, an Argument value must correspond
+ * to an existing entity in the domain of entities denoted by the Argument type.
+ */
+ public boolean isExisting() {
+ return isExisting(flags);
+ }
+
+ /**
+ * If this method returns <code>true</code>, an Argument value must <i>not</i> correspond
+ * to an existing entity in the domain of entities denoted by the Argument type.
+ */
+ public boolean isNonexistent() {
+ return isNonexistent(flags);
+ }
+
+ /**
+ * If this method returns <code>true</code>, the flags say that the corresponding Argument
+ * must be bound to an argument in a CommandLine if it is used in a given concrete syntax.
+ */
+ public static boolean isMandatory(int flags) {
+ return (flags & MANDATORY) != 0;
+ }
+
+ /**
+ * If this method returns <code>true</code>, the flags say that the corresponding Argument
+ * need not be bound to an argument in a CommandLine if it is used in a given concrete syntax.
+ */
+ public static boolean isOptional(int flags) {
+ return (flags & MANDATORY) == 0;
+ }
+
+ /**
+ * If this method returns <code>true</code>, the corresponding Argument may have
+ * multiple instances in a CommandLine.
+ */
+ public static boolean isMultiple(int flags) {
+ return (flags & MULTIPLE) != 0;
+ }
+
+ /**
+ * If this method returns <code>true</code>, the corresponding Argument must have at
+ * most one instance in a CommandLine.
+ */
+ public static boolean isSingle(int flags) {
+ return (flags & MULTIPLE) == 0;
+ }
+
+ /**
+ * If this method returns <code>true</code>, the corresponding Argument value must denote
+ * an existing entity.
+ */
+ public static boolean isExisting(int flags) {
+ return (flags & EXISTING) != 0;
+ }
+
+ /**
+ * If this method returns <code>true</code>, the corresponding Argument value must
+ * <i>not</i> denote an existing entity.
+ */
+ public boolean isNonexistent(int flags) {
+ return (flags & NONEXISTENT) != 0;
+ }
+
+ /**
* The label is the application's identifier for the Argument. It is used to identify
* the Argument in a concrete syntax specification. It can also be used by the
* application for name lookup of a bound argument's values.
@@ -207,12 +378,18 @@
* the caller should treat the Token as consumed.
*
* @param value the token that will supply the Argument's value.
+ * @param flags extra flags from the syntax system. These will be OR'ed with
+ * the Arguments existing flags. Note the cardinality flags cannot be
+ * overridden.
*/
- public final void accept(Token value) throws CommandSyntaxException {
+ public final void accept(Token value, int flags)
+ throws CommandSyntaxException, IllegalArgumentException {
if (isSet() && !isMultiple()) {
throw new SyntaxMultiplicityException("this argument cannot be repeated");
}
- addValue(doAccept(value));
+ flags = (flags & ~NONOVERRIDABLE_FLAGS) | this.flags;
+ checkFlags(flags);
+ addValue(doAccept(value, flags));
}
/**
@@ -220,8 +397,9 @@
* should either return a non-null V to be accepted, or throw an exception.
*
* @param value the token that will supply the Argument's value.
+ * @param flags the flags to be used.
*/
- protected abstract V doAccept(Token value) throws CommandSyntaxException;
+ protected abstract V doAccept(Token value, int flags) throws CommandSyntaxException;
/**
* Perform argument completion on the supplied (partial) argument value. The
@@ -235,40 +413,29 @@
* @param completion the CompletionInfo object for registering any completions.
* @param partial the argument string to be completed.
*/
- public void complete(CompletionInfo completion, String partial) {
- // set no completion
+ public final void complete(CompletionInfo completion, String partial, int flags) {
+ if (isSet() && !isMultiple()) {
+ throw new SyntaxMultiplicityException("this argument cannot be repeated");
+ }
+ flags = (flags & ~NONOVERRIDABLE_FLAGS) | this.flags;
+ checkFlags(flags);
+ doComplete(completion, partial, flags);
}
-
- /**
- * Test if sufficient values have been bound to the Argument to satisfy the
- * the Argument's specified cardinality constraints.
- */
- public boolean isSatisfied() {
- return !isMandatory() || isSet();
- }
-
- /**
- * If this method returns <code>true</code>, this element may have
- * multiple instances in a CommandLine.
- */
- public boolean isMultiple() {
- return multiple;
- }
-
- /**
- * If this method returns <code>true</code>, an Argument value must correspond
- * to an existing entity in the domain of entities denoted by the Argument type.
- */
- public boolean isExisting() {
- return existing;
- }
/**
- * If this method returns <code>true</code>, an Argument value must <i>not</i> correspond
- * to an existing entity in the domain of entities denoted by the Argument type.
+ * Perform argument completion on the supplied (partial) argument value. The
+ * results of the completion should be added to the supplied CompletionInfo.
+ * <p>
+ * The default behavior is to set no completion.
+ * Subtypes of Argument should override this method if they are capable of doing
+ * non-trivial completion. Completions should be registered by calling one
+ * of the 'addCompletion' methods on the CompletionInfo.
+ *
+ * @param completion the CompletionInfo object for registering any completions.
+ * @param partial the argument string to be completed.
*/
- public boolean isNonexistent() {
- return nonexistent;
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
+ // set no completion
}
void setBundle(ArgumentBundle bundle) {
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/ArgumentBundle.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/ArgumentBundle.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/ArgumentBundle.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -111,7 +111,7 @@
try {
doParse(commandLine, syntaxes, null);
for (Argument<?> element : arguments) {
- if (!element.isSatisfied() && element.isMandatory()) {
+ if (!element.isSet() && element.isMandatory()) {
throw new CommandSyntaxException(
"Command syntax error: required argument '"
+ element.getLabel() + "' not supplied");
@@ -195,7 +195,7 @@
return new EmptySyntax("default", null);
} else if (arguments.length == 1) {
String label = arguments[0].getLabel();
- return new OptionSyntax(label, label, null);
+ return new OptionSyntax(label, label, null, null);
} else {
// A better default syntax would only allow one Option repetition
// for any Argument that accepts only one value, and would use mandatory
@@ -203,7 +203,7 @@
Syntax[] syntaxes = new OptionSyntax[arguments.length];
for (int i = 0; i < syntaxes.length; i++) {
String label = arguments[i].getLabel();
- syntaxes[i] = new OptionSyntax(label, label, null);
+ syntaxes[i] = new OptionSyntax(label, label, null, null);
}
return new PowersetSyntax("default", syntaxes);
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/ArgumentSyntax.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/ArgumentSyntax.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/ArgumentSyntax.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -32,21 +32,23 @@
public class ArgumentSyntax extends Syntax {
private final String argName;
+ private final String flags;
- public ArgumentSyntax(String label, String argName, String description) {
+ public ArgumentSyntax(String label, String argName, String flags, String description) {
super(label, description);
this.argName = argName;
+ this.flags = flags;
if (argName.length() == 0) {
throw new IllegalArgumentException("empty argName");
}
}
public ArgumentSyntax(String label, String argName) {
- this(label, argName, null);
+ this(label, argName, null, null);
}
public ArgumentSyntax(String argName) {
- this(null, argName, null);
+ this(null, argName, null, null);
}
@Override
@@ -61,12 +63,19 @@
@Override
public String toString() {
- return "ArgumentSyntax{" + super.toString() + ",argName=" + argName + "}";
+ return "ArgumentSyntax{" + super.toString() + ",argName=" +
+ argName + ",flags=" + flags + "}";
}
@Override
public MuSyntax prepare(ArgumentBundle bundle) {
- return new MuArgument(label, argName);
+ int flags;
+ if (this.flags == null || this.flags.length() == 0) {
+ flags = 0;
+ } else {
+ flags = bundle.getArgument(argName).namesToFlags(this.flags);
+ }
+ return new MuArgument(label, argName, flags);
}
public String getArgName() {
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/ClassNameArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/ClassNameArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/ClassNameArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -39,7 +39,7 @@
}
@Override
- protected String doAccept(Token token) throws CommandSyntaxException {
+ protected String doAccept(Token token, int flags) throws CommandSyntaxException {
return token.text;
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/CountryArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/CountryArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/CountryArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -41,7 +41,7 @@
}
@Override
- protected String doAccept(Token token) throws CommandSyntaxException {
+ protected String doAccept(Token token, int flags) throws CommandSyntaxException {
if (validCountries.contains(token.text)) {
return token.text;
} else {
@@ -50,7 +50,7 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
for (String country : validCountries) {
if (country.startsWith(partial)) {
completion.addCompletion(country);
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/DeviceArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/DeviceArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/DeviceArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -54,7 +54,7 @@
}
@Override
- protected Device doAccept(Token token) throws CommandSyntaxException {
+ protected Device doAccept(Token token, int flags) throws CommandSyntaxException {
try {
final DeviceManager devMgr = getDeviceManager();
final Device device = devMgr.getDevice(token.text);
@@ -70,7 +70,7 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
final DeviceManager devMgr = getDeviceManager();
// collect matching devices
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/EnumArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/EnumArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/EnumArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -60,7 +60,7 @@
}
@Override
- protected E doAccept(Token token) throws CommandSyntaxException {
+ protected E doAccept(Token token, int flags) throws CommandSyntaxException {
try {
return E.valueOf(clazz, token.text);
} catch (IllegalArgumentException ex) {
@@ -69,7 +69,7 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
for (E e : clazz.getEnumConstants()) {
String eName = e.name();
if (eName.startsWith(partial)) {
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/FileArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/FileArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/FileArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -32,11 +32,44 @@
/**
* This argument class performs completion against the file system namespace. This
* Argument class understands the {@link Argument#EXISTING} and {@link Argument#NONEXISTENT}
- * flags when accepting argument values, but not (yet) when completing them.
+ * flags when accepting argument values. Neither {@link Argument#EXISTING} or
+ * {@link Argument#NONEXISTENT} currently affect completion. (You might expect that
+ * {@link Argument#NONEXISTENT} would suppress completion, but consider that the user
+ * may want to complete the directory path for some file to be created by a command.)
+ * <p>
+ * FileArgument normally treats pathname components starting with a "-" as invalid pathnames
+ * and won't accept them. (The rationale is that they are probably a misplaced or unknown
+ * option names.) This behavior can be changed using the {@link #ALLOW_DODGY_NAMES} flag.
+ * <p>
+ * Some commands use "-" to denote (for example) "standard input" instead of a file named
+ * "-". To support this, FileArgument provides a {@link #HYPHEN_IS_SPECIAL} flag which
+ * suppresses the {@link Argument#EXISTING} and {@link Argument#NONEXISTENT} flags so that
+ * a "-" argument is always accepted. It is up to the command to deal with the resulting
+ * {@code File("-")} instance, which of course should not be opened in the normal way.
+ * (Note: this is an experimental feature, and may be replaced with a conceptually cleaner
+ * solution in the future.)
*
* @author cr...@jn...
*/
public class FileArgument extends Argument<File> {
+
+ /**
+ * This Argument flag tells the FileArgument to accept filenames that,
+ * while strictly legal, will cause problems. At the moment, this means
+ * pathnames where one or more component names starts with a '-'. (Such
+ * names may be problematic for some commands, and are probably entered
+ * by mistake.)
+ */
+ public static final int ALLOW_DODGY_NAMES = 0x00010000;
+
+ /**
+ * This Argument flag tells the FileArgument that the command will
+ * interpret {@code File("-")} as meaning something other than a regular
+ * pathname, and that FileArgument should allow "-" as a valid argument
+ * or completion, not withstanding the existence of a real file with
+ * that name. This flag cannot be set by a Syntax.
+ */
+ public static final int HYPHEN_IS_SPECIAL = 0x01000000;
public FileArgument(String label, int flags, String description) {
super(label, flags, new File[0], description);
@@ -48,15 +81,32 @@
@Override
@DoPrivileged
- protected File doAccept(Token token) throws CommandSyntaxException {
+ protected File doAccept(Token token, int flags) throws CommandSyntaxException {
if (token.text.length() > 0) {
File file = new File(token.text);
- if (isExisting() && !file.exists()) {
- throw new CommandSyntaxException("this file or directory does not exist");
+ if ((flags & HYPHEN_IS_SPECIAL) == 0 || !file.getPath().equals("-")) {
+ if (isExisting(flags) && !file.exists()) {
+ throw new CommandSyntaxException("this file or directory does not exist");
+ }
+ if (isNonexistent(flags) && file.exists()) {
+ throw new CommandSyntaxException("this file or directory already exist");
+ }
+ if ((flags & ALLOW_DODGY_NAMES) == 0) {
+ File f = file;
+ do {
+ // This assumes that option names start with '-'.
+ if (f.getName().startsWith("-")) {
+ if (f == file && !file.isAbsolute() && f.getParent() == null) {
+ // The user most likely meant this to be an option name ...
+ throw new CommandSyntaxException("unexpected or unknown option");
+ } else {
+ throw new CommandSyntaxException("file or directory name starts with a '-'");
+ }
+ }
+ f = f.getParentFile();
+ } while (f != null);
+ }
}
- if (isNonexistent() && file.exists()) {
- throw new CommandSyntaxException("this file or directory already exist");
- }
return file;
} else {
throw new CommandSyntaxException("invalid file name");
@@ -64,7 +114,8 @@
}
@Override
- public void complete(final CompletionInfo completion, final String partial) {
+ public void doComplete(final CompletionInfo completion,
+ final String partial, final int flags) {
// Get last full directory from the partial pathname.
final int idx = partial.lastIndexOf(File.separatorChar);
final String dir;
@@ -121,10 +172,26 @@
(tmp == 2 && partial.endsWith("."))) {
completion.addCompletion(partial + File.separatorChar, true);
}
+
+ // Add "-" as a possible completion?
+ if ((flags & HYPHEN_IS_SPECIAL) != 0) {
+ completion.addCompletion("-");
+ }
}
@Override
protected String argumentKind() {
return "file";
}
+
+ @Override
+ public int nameToFlag(String name) throws IllegalArgumentException {
+ if (name.equals("ALLOW_DODGY_NAMES")) {
+ return ALLOW_DODGY_NAMES;
+ } else if (name.equals("HYPHEN_IS_SPECIAL")) {
+ return HYPHEN_IS_SPECIAL;
+ } else{
+ return super.nameToFlag(name);
+ }
+ }
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/FlagArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/FlagArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/FlagArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -38,7 +38,7 @@
}
@Override
- protected Boolean doAccept(Token token) throws CommandSyntaxException {
+ protected Boolean doAccept(Token token, int flags) throws CommandSyntaxException {
return Boolean.TRUE;
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/HostNameArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/HostNameArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/HostNameArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -48,7 +48,7 @@
}
@Override
- protected String doAccept(Token token) throws CommandSyntaxException {
+ protected String doAccept(Token token, int flags) throws CommandSyntaxException {
return token.text;
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/IntegerArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/IntegerArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/IntegerArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -55,7 +55,7 @@
}
@Override
- protected Integer doAccept(Token token) throws CommandSyntaxException {
+ protected Integer doAccept(Token token, int flags) throws CommandSyntaxException {
try {
int tmp = Integer.parseInt(token.text);
if (tmp < min || tmp > max) {
@@ -68,7 +68,7 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
// FIXME ... maybe someone could figure out how to partial
// completion efficiently when max - min is large?
if (max - min >= 0 && max - min < COMPLETION_THRESHOLD) {
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/KeyboardLayoutArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/KeyboardLayoutArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/KeyboardLayoutArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -46,12 +46,12 @@
}
@Override
- protected String doAccept(Token token) throws CommandSyntaxException {
+ protected String doAccept(Token token, int flags) throws CommandSyntaxException {
return token.text;
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
try {
KeyboardLayoutManager mgr = InitialNaming.lookup(KeyboardLayoutManager.NAME);
// collect matching devices
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/LanguageArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/LanguageArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/LanguageArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -28,7 +28,7 @@
import org.jnode.shell.CommandLine.Token;
/**
- * This argument accepts an ISO country code.
+ * This argument accepts an ISO language code.
*
* @author cr...@jn...
*/
@@ -41,7 +41,7 @@
}
@Override
- protected String doAccept(Token token) throws CommandSyntaxException {
+ protected String doAccept(Token token, int flags) throws CommandSyntaxException {
if (validLanguages.contains(token.text)) {
return token.text;
} else {
@@ -50,7 +50,7 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
for (String language : validLanguages) {
if (language.startsWith(partial)) {
completion.addCompletion(language);
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLoggerArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLoggerArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/Log4jLoggerArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -48,7 +48,7 @@
* Any token is an acceptable Logger name.
*/
@Override
- protected Logger doAccept(Token value) throws CommandSyntaxException {
+ protected Logger doAccept(Token value, int flags) throws CommandSyntaxException {
return Logger.getLogger(value.text);
}
@@ -56,7 +56,7 @@
* Complete against existing logger names.
*/
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
Enumeration<?> en = LogManager.getCurrentLoggers();
while (en.hasMoreElements()) {
String loggerName = ((Logger) en.nextElement()).getName();
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/LongArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/LongArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/LongArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -56,7 +56,7 @@
}
@Override
- protected Long doAccept(Token token) throws CommandSyntaxException {
+ protected Long doAccept(Token token, int flags) throws CommandSyntaxException {
try {
long tmp = Long.parseLong(token.text);
if (tmp < min || tmp > max) {
@@ -69,7 +69,7 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
// FIXME ... maybe someone could figure out how to partial
// completion efficiently when max - min is large?
if (max - min >= 0 && max - min < COMPLETION_THRESHOLD) {
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/MappedArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/MappedArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/MappedArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -62,7 +62,7 @@
* Complete partial against the domain of the valueMap.
*/
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
if (caseInsensitive) {
partial = partial.toLowerCase();
}
@@ -77,7 +77,7 @@
* Accept token if it is in the domain of the valueMap.
*/
@Override
- protected V doAccept(Token token) throws CommandSyntaxException {
+ protected V doAccept(Token token, int flags) throws CommandSyntaxException {
String t = caseInsensitive ? token.text.toLowerCase() : token.text;
V value = valueMap.get(t);
if (value == null) {
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/MuArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/MuArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/MuArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -29,17 +29,19 @@
public class MuArgument extends MuSyntax {
private final String argName;
+ private final int flags;
public MuArgument(String argName) {
- this (null, argName);
+ this (null, argName, 0);
}
- public MuArgument(String label, String argName) {
+ public MuArgument(String label, String argName, int flags) {
super(label);
if (argName.length() == 0) {
throw new IllegalArgumentException("empty argName");
}
this.argName = argName;
+ this.flags = flags;
}
@Override
@@ -63,4 +65,8 @@
}
return this;
}
+
+ public int getFlags() {
+ return flags;
+ }
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/MuParser.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/MuParser.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/MuParser.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -213,13 +213,15 @@
}
break;
case ARGUMENT:
- String argName = ((MuArgument) syntax).getArgName();
+ MuArgument muArg = (MuArgument) syntax;
+ String argName = muArg.getArgName();
+ int flags = muArg.getFlags();
Argument<?> arg = bundle.getArgument(argName);
try {
if (source.hasNext()) {
token = source.next();
if (completion == null || source.hasNext() || source.whitespaceAfterLast()) {
- arg.accept(token);
+ arg.accept(token, flags);
if (!backtrackStack.isEmpty()) {
backtrackStack.getFirst().argsModified.add(arg);
if (DEBUG) {
@@ -227,13 +229,13 @@
}
}
} else {
- arg.complete(completion, token.text);
+ arg.complete(completion, token.text, flags);
completion.setCompletionStart(token.start);
backtrack = true;
}
} else {
if (completion != null) {
- arg.complete(completion, "");
+ arg.complete(completion, "", flags);
}
backtrack = true;
}
@@ -247,10 +249,11 @@
}
break;
case PRESET:
- MuPreset preset = (MuPreset) syntax;
- arg = bundle.getArgument(preset.getArgName());
+ MuPreset muPreset = (MuPreset) syntax;
+ arg = bundle.getArgument(muPreset.getArgName());
+ flags = muPreset.getFlags();
try {
- arg.accept(new CommandLine.Token(preset.getPreset()));
+ arg.accept(new CommandLine.Token(muPreset.getPreset()), flags);
if (!backtrackStack.isEmpty()) {
backtrackStack.getFirst().argsModified.add(arg);
if (DEBUG) {
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/MuPreset.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/MuPreset.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/MuPreset.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -30,18 +30,20 @@
private final String argName;
private final String preset;
+ private final int flags;
public MuPreset(String argName, String preset) {
- this (null, argName, preset);
+ this(null, argName, preset, 0);
}
- public MuPreset(String label, String argName, String preset) {
+ public MuPreset(String label, String argName, String preset, int flags) {
super(label);
if (argName.length() == 0) {
throw new IllegalArgumentException("empty argName");
}
this.argName = argName;
this.preset = preset;
+ this.flags = flags;
}
@Override
@@ -69,4 +71,8 @@
public String getPreset() {
return preset;
}
+
+ public int getFlags() {
+ return flags;
+ }
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/OptionSetSyntax.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/OptionSetSyntax.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/OptionSetSyntax.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -52,7 +52,7 @@
}
@Override
- protected Boolean doAccept(Token token) throws CommandSyntaxException {
+ protected Boolean doAccept(Token token, int argumentFlags) throws CommandSyntaxException {
String value = token.text;
int len = value.length();
if (len < 2 || value.charAt(0) != '-') {
@@ -64,7 +64,7 @@
boolean found = false;
for (OptionSyntax flagOption : flagOptions) {
if (shortOptName.equals(flagOption.getShortOptName())) {
- bundle.getArgument(flagOption).accept(new Token(shortOptName));
+ bundle.getArgument(flagOption).accept(new Token(shortOptName), 0);
found = true;
break;
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/OptionSyntax.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/OptionSyntax.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/OptionSyntax.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -35,34 +35,35 @@
private final String longOptName;
private final String shortOptName;
- public OptionSyntax(String argName, String optionName, char optionChar, String description) {
- super(null, argName, description);
+ public OptionSyntax(String argName, String optionName, char optionChar,
+ String flags, String description) {
+ super(null, argName, flags, description);
this.longOptName = "--" + optionName;
this.shortOptName = "-" + optionChar;
}
- public OptionSyntax(String argName, char optionChar, String description) {
- super(null, argName, description);
+ public OptionSyntax(String argName, char optionChar, String flags, String description) {
+ super(null, argName, flags, description);
this.longOptName = null;
this.shortOptName = "-" + optionChar;
}
- public OptionSyntax(String argName, String optionName, String description) {
- super(null, argName, description);
+ public OptionSyntax(String argName, String optionName, String flags, String description) {
+ super(null, argName, flags, description);
this.longOptName = "--" + optionName;
this.shortOptName = null;
}
public OptionSyntax(String argName, String optionName, char optionChar) {
- this(argName, optionName, optionChar, null);
+ this(argName, optionName, optionChar, null, null);
}
public OptionSyntax(String argName, char optionChar) {
- this(argName, optionChar, null);
+ this(argName, optionChar, null, null);
}
public OptionSyntax(String argName, String optionName) {
- this(argName, optionName, null);
+ this(argName, optionName, null, null);
}
@Override
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/PluginArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/PluginArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/PluginArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -40,7 +40,7 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
try {
// get the plugin manager
final PluginManager piMgr = InitialNaming.lookup(PluginManager.NAME);
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/PropertyNameArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/PropertyNameArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/PropertyNameArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -45,12 +45,12 @@
}
@Override
- protected String doAccept(Token token) throws CommandSyntaxException {
+ protected String doAccept(Token token, int flags) throws CommandSyntaxException {
return token.text;
}
@Override
- public void complete(CompletionInfo completion, String partial) {
+ public void doComplete(CompletionInfo completion, String partial, int flags) {
for (Object key : System.getProperties().keySet()) {
String name = (String) key;
if (name.startsWith(partial)) {
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/SizeArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/SizeArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/SizeArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -20,7 +20,6 @@
package org.jnode.shell.syntax;
-import org.jnode.driver.console.CompletionInfo;
import org.jnode.shell.CommandLine.Token;
import org.jnode.util.BinaryScaleFactor;
import org.jnode.util.DecimalScaleFactor;
@@ -45,7 +44,7 @@
}
@Override
- protected Long doAccept(Token token) throws CommandSyntaxException {
+ protected Long doAccept(Token token, int flags) throws CommandSyntaxException {
String str = token.text;
ScaleFactor factor = scaleFactor(str);
if (factor != null) {
@@ -72,11 +71,6 @@
}
@Override
- public void complete(CompletionInfo completion, String partial) {
- // No completion for now
- }
-
- @Override
protected String state() {
return super.state() + "binaryScaling=" + binaryScaling;
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/StringArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/StringArgument.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/StringArgument.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -42,7 +42,7 @@
}
@Override
- protected String doAccept(Token token) throws CommandSyntaxException {
+ protected String doAccept(Token token, int flags) throws CommandSyntaxException {
return token.text;
}
Modified: trunk/shell/src/shell/org/jnode/shell/syntax/SyntaxSpecLoader.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/syntax/SyntaxSpecLoader.java 2009-04-11 14:18:16 UTC (rev 5248)
+++ trunk/shell/src/shell/org/jnode/shell/syntax/SyntaxSpecLoader.java 2009-04-12 01:05:05 UTC (rev 5249)
@@ -84,21 +84,22 @@
}
String shortName = syntaxElement.getAttribute("shortName");
String longName = syntaxElement.getAttribute("longName");
+ String flags = syntaxElement.getAttribute("flags");
if (shortName == null) {
if (longName == null) {
throw new SyntaxFailureException(
"<option> element has must have a 'shortName' or 'longName' attribute");
}
- return new OptionSyntax(argLabel, longName, description);
+ return new OptionSyntax(argLabel, longName, flags, description);
} else {
if (shortName.length() != 1) {
throw new SyntaxFailureException(
"<option> elements 'shortName' attribute must be one character long");
}
if (longName == null) {
- return new OptionSyntax(argLabel, shortName.charAt(0), description);
+ return new OptionSyntax(argLabel, shortName.charAt(0), flags, description);
} else {
- return new OptionSyntax(argLabel, longName, shortName.charAt(0), description);
+ return new OptionSyntax(argLabel, longName, shortName.charAt(0), flags, description);
}
}
} else if (kind.equals("powerset")) {
@@ -135,11 +136,12 @@
return new OptionalSyntax(label, description, eager, seq);
} else if (kind.equals("argument")) {
String argLabel = syntaxElement.getAttribute("argLabel");
+ String flags = syntaxElement.getAttribute("flags");
if (argLabel == null) {
System.out.println(syntaxElement);
throw new SyntaxFailureException("<argument> element has no 'argLabel' attribute");
}
- return new ArgumentSyntax(label, argLabel, description);
+ return new ArgumentSyntax(label, argLabel, flags, description);
} else if (kind.equ...
[truncated message content] |