diff --git a/.gitignore b/.gitignore
index d3cee95d..5c940932 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,6 @@ target/
/*.log
/.idea
-/*.iml
\ No newline at end of file
+/*.iml
+/*.ipr
+/*.iws
diff --git a/src/main/java/org/springframework/shell/core/SimpleParser.java b/src/main/java/org/springframework/shell/core/SimpleParser.java
index 7f963905..9744238f 100644
--- a/src/main/java/org/springframework/shell/core/SimpleParser.java
+++ b/src/main/java/org/springframework/shell/core/SimpleParser.java
@@ -45,7 +45,7 @@ import org.springframework.util.StringUtils;
/**
* Default implementation of {@link Parser}.
- *
+ *
* @author Ben Alex
* @since 1.0
*/
@@ -81,7 +81,7 @@ public class SimpleParser implements Parser {
/**
* get all mandatory options keys. For the options with multiple keys, the keys will be in one row.
- *
+ *
* @param cliOptions options
* @return mandatory options keys
*/
@@ -91,7 +91,7 @@ public class SimpleParser implements Parser {
/**
* get all options key.
- *
+ *
* @param cliOptions
* @param includeOptionalOptions
* @return options keys
@@ -393,7 +393,7 @@ public class SimpleParser implements Parser {
/**
* Normalises the given raw user input string ready for parsing
- *
+ *
* @param rawInput the string to normalise; can't be null
* @return a non-null string
*/
@@ -407,12 +407,12 @@ public class SimpleParser implements Parser {
Set cliOptionKeySet = new LinkedHashSet();
for (CliOption cliOption : cliOptions) {
for (String key : cliOption.key()) {
- cliOptionKeySet.add(key.toLowerCase());
+ cliOptionKeySet.add(key);
}
}
Set unavailableOptions = new LinkedHashSet();
for (String suppliedOption : options.keySet()) {
- if (!cliOptionKeySet.contains(suppliedOption.toLowerCase())) {
+ if (!cliOptionKeySet.contains(suppliedOption)) {
unavailableOptions.add(suppliedOption);
}
}
@@ -499,7 +499,8 @@ public class SimpleParser implements Parser {
String bufferToReturn = null;
String lastWord = null;
- next_buffer_loop: for (int bufferIndex = 0; bufferIndex < buffer.length(); bufferIndex++) {
+ next_buffer_loop:
+ for (int bufferIndex = 0; bufferIndex < buffer.length(); bufferIndex++) {
String bufferSoFarIncludingThis = buffer.substring(0, bufferIndex + 1);
String bufferRemaining = buffer.substring(bufferIndex + 1);
@@ -649,7 +650,7 @@ public class SimpleParser implements Parser {
for (String value : cmd.value()) {
if (buffer.startsWith(value) || value.startsWith(buffer)) {
results.add(new Completion(value)); // no space at the end, as there's no need to continue the
- // command further
+ // command further
}
}
candidates.addAll(results);
@@ -750,7 +751,7 @@ public class SimpleParser implements Parser {
// option key/value pair)
if (lastOptionKey == null
|| (!"".equals(lastOptionKey) && !"".equals(lastOptionValue) && translated.endsWith(" ") && !tokenizer
- .openingQuotesHaveNotBeenClosed())) {
+ .openingQuotesHaveNotBeenClosed())) {
// We have either NEVER specified an option key/value pair
// OR we have specified a full option key/value pair
@@ -978,7 +979,7 @@ public class SimpleParser implements Parser {
/**
* populate completion for mandatory options
- *
+ *
* @param translated user's input
* @param unspecified unspecified options
* @param value the option key
@@ -1002,7 +1003,7 @@ public class SimpleParser implements Parser {
}
public void obtainHelp(
- @CliOption(key = { "", "command" }, optionContext = "availableCommands", help = "Command name to provide help for")
+ @CliOption(key = {"", "command"}, optionContext = "availableCommands", help = "Command name to provide help for")
String buffer) {
synchronized (mutex) {
if (buffer == null) {
diff --git a/src/test/java/org/springframework/shell/core/SimpleParserTests.java b/src/test/java/org/springframework/shell/core/SimpleParserTests.java
index 46ce700d..c0e241df 100644
--- a/src/test/java/org/springframework/shell/core/SimpleParserTests.java
+++ b/src/test/java/org/springframework/shell/core/SimpleParserTests.java
@@ -37,6 +37,8 @@ import org.hamcrest.DiagnosingMatcher;
import org.hamcrest.Matcher;
import org.junit.Assert;
import org.junit.Test;
+
+import org.springframework.shell.converters.StringConverter;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.springframework.shell.event.ParseResult;
@@ -428,6 +430,17 @@ public class SimpleParserTests {
assertThat(result, nullValue(ParseResult.class));
}
+ @Test
+ public void testMixedCaseOptions_SHL_98() {
+ parser.add(new MixedCaseOptions());
+ parser.add(new StringConverter());
+ ParseResult result = parser.parse("foo --upPer bar");
+ assertThat(result.getMethod().getName(), equalTo("foo"));
+
+ result = parser.parse("foo --upper fizz");
+ assertThat(result, nullValue());
+ }
+
/**
* Return a matcher that asserts that a completion, when added to {@link #buffer} at the given {@link #offset},
* indeed matches the provided matcher.
@@ -523,6 +536,18 @@ public class SimpleParserTests {
}
}
+ public static class MixedCaseOptions implements CommandMarker {
+ @CliCommand(value = "foo")
+ public String foo(@CliOption(key = "upPer")
+ String arg) {
+ return "foo " + arg;
+ }
+
+
+ }
+
+
+
public static class StringCompletions implements Converter {
private final List completions;