Handle quotes escaping in completions
This commit is contained in:
@@ -808,10 +808,11 @@ public class SimpleParser implements Parser {
|
|||||||
for (Completion currentValue : allValues) {
|
for (Completion currentValue : allValues) {
|
||||||
// Only add the result **if** what they've typed is compatible *AND* they haven't
|
// Only add the result **if** what they've typed is compatible *AND* they haven't
|
||||||
// already typed it in full
|
// already typed it in full
|
||||||
if (currentValue.getValue().toLowerCase().startsWith(lastOptionValue.toLowerCase())
|
String proposal = currentValue.getValue();
|
||||||
&& lastOptionValue.length() < currentValue.getValue().length()
|
if (proposal.toLowerCase().startsWith(lastOptionValue.toLowerCase())
|
||||||
|
&& lastOptionValue.length() < proposal.length()
|
||||||
&& (!tokenizer.lastValueIsComplete())) {
|
&& (!tokenizer.lastValueIsComplete())) {
|
||||||
results.add(new Completion(currentValue.getValue() + suffix, currentValue
|
results.add(new Completion(tokenizer.escape(proposal) + suffix, currentValue
|
||||||
.getFormattedValue(), currentValue.getHeading(), currentValue.getOrder()));
|
.getFormattedValue(), currentValue.getHeading(), currentValue.getOrder()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -822,7 +823,7 @@ public class SimpleParser implements Parser {
|
|||||||
|
|
||||||
if (results.size() == 1) {
|
if (results.size() == 1) {
|
||||||
String suggestion = results.iterator().next().getValue().trim();
|
String suggestion = results.iterator().next().getValue().trim();
|
||||||
if (suggestion.equals(lastOptionValue)) {
|
if (suggestion.equals(tokenizer.escape(lastOptionValue))) {
|
||||||
// They have pressed TAB in the default value, and the default value has already
|
// They have pressed TAB in the default value, and the default value has already
|
||||||
// been provided as an explicit option
|
// been provided as an explicit option
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -183,6 +183,13 @@ public class Tokenizer {
|
|||||||
return !openingQuotesHaveNotBeenClosed && lastValueDelimiter != ' ';
|
return !openingQuotesHaveNotBeenClosed && lastValueDelimiter != ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply delimiter escaping to the given string, using the actual delimiter that was used for the last value.
|
||||||
|
*/
|
||||||
|
public String escape(String value) {
|
||||||
|
return value.replace("" + lastValueDelimiter, "" + ESCAPE_CHAR + lastValueDelimiter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consume a full @code{--key value} pair *unless* we're at the very end, in which case allow for @code {--key},
|
* Consume a full @code{--key value} pair *unless* we're at the very end, in which case allow for @code {--key},
|
||||||
* using "" for the value.
|
* using "" for the value.
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import java.util.List;
|
|||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
import org.hamcrest.DiagnosingMatcher;
|
import org.hamcrest.DiagnosingMatcher;
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.shell.core.annotation.CliCommand;
|
import org.springframework.shell.core.annotation.CliCommand;
|
||||||
import org.springframework.shell.core.annotation.CliOption;
|
import org.springframework.shell.core.annotation.CliOption;
|
||||||
@@ -163,7 +162,6 @@ public class SimpleParserTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("TODO")
|
|
||||||
public void testArgumentValueWithEscapedQuotes() {
|
public void testArgumentValueWithEscapedQuotes() {
|
||||||
parser.add(new MyCommands());
|
parser.add(new MyCommands());
|
||||||
parser.add(new StringCompletions(Arrays.asList("he said \"hello\" to me")));
|
parser.add(new StringCompletions(Arrays.asList("he said \"hello\" to me")));
|
||||||
|
|||||||
Reference in New Issue
Block a user