Author: lincolnthree
Date: 2010-07-14 12:03:24 -0400 (Wed, 14 Jul 2010)
New Revision: 13390
Modified:
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java
Log:
Quoted strings now respected on command line
Modified:
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java
===================================================================
---
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java 2010-07-14
10:47:59 UTC (rev 13389)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java 2010-07-14
16:03:24 UTC (rev 13390)
@@ -25,6 +25,8 @@
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
@@ -107,10 +109,20 @@
{
Queue<String> tokens = new LinkedList<String>();
- for (String token : line.split("\\s+"))
+ // -------------------------------(0-(1------)---(2---))----------
+ Matcher matcher =
Pattern.compile("\"([^\"]*?)\"|(\\S+)").matcher(line);
+ while (matcher.find())
{
- tokens.add(token);
+ if (matcher.group(1) != null)
+ {
+ tokens.add(matcher.group(1));
+ }
+ else
+ {
+ tokens.add(matcher.group());
+ }
}
+
return tokens;
}
@@ -118,7 +130,9 @@
{
Map<OptionMetadata, Object> valueMap = new HashMap<OptionMetadata,
Object>();
- CommandParser commandParser = new CompositeCommandParser(new
NamedBooleanOptionParser(), new NamedValueOptionParser(), new
NamedValueVarargsOptionParser(), new OrderedValueOptionParser(), new
OrderedValueVarargsOptionParser(), new ParseErrorParser());
+ CommandParser commandParser = new CompositeCommandParser(new
NamedBooleanOptionParser(),
+ new NamedValueOptionParser(), new NamedValueVarargsOptionParser(), new
OrderedValueOptionParser(),
+ new OrderedValueVarargsOptionParser(), new ParseErrorParser());
commandParser.parse(command, valueMap, tokens);
Show replies by date