Repository: incubator-geode Updated Branches: refs/heads/develop 8899fc8d7 -> f8f9454d4
GEODE-1598: fix autocomplete for first option and repeat tabs * This closes #185 Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/f8f9454d Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/f8f9454d Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/f8f9454d Branch: refs/heads/develop Commit: f8f9454d4a3b996b7d5b6e031d7197f40ace2b28 Parents: 8899fc8 Author: gmeilen <[email protected]> Authored: Fri Jul 1 11:21:39 2016 -0700 Committer: Kirk Lund <[email protected]> Committed: Fri Jul 1 11:30:34 2016 -0700 ---------------------------------------------------------------------- .../management/internal/cli/GfshParser.java | 42 +++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f8f9454d/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java index 7fc7295..6e91b64 100755 --- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java +++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/GfshParser.java @@ -338,14 +338,24 @@ public class GfshParser implements Parser { boolean updatedDesiredCursorPosition = false; if (!userOptionSet.areOptionsPresent()) { - int walkBackwards = remainingBuffer.length() - 1; - while (remainingBuffer.charAt(walkBackwards) != '-') { - walkBackwards--; + if (remainingBuffer.contains("-")) { + int walkBackwards = remainingBuffer.length() - 1; + while (remainingBuffer.charAt(walkBackwards) != '-' && walkBackwards > 0) { + walkBackwards--; + } + while (remainingBuffer.charAt(walkBackwards) == '-' && walkBackwards > 0) { + walkBackwards--; + } + while (remainingBuffer.charAt(walkBackwards) == ' ' && walkBackwards > 0) { + walkBackwards--; + } + if (walkBackwards > 0) { + walkBackwards += 2; + desiredCursorPosition += walkBackwards; + } + updatedDesiredCursorPosition = true; } - walkBackwards -= 2; - desiredCursorPosition += walkBackwards; - updatedDesiredCursorPosition = true; - } + } // gfsh>start server --name=server1 --lo for (Option option : commandTarget.getOptionParser().getOptions()) { if (!updatedDesiredCursorPosition && userOptionSet.hasOption(option)) { @@ -582,21 +592,25 @@ public class GfshParser implements Parser { } } + // Calculate the cursor position int newCursor = desiredCursorPosition + ((userOptionSet != null) ? userOptionSet.getNoOfSpacesRemoved() : 0); String subString = remainingBuffer; if (newCursor != cursorStart) { - subString = remainingBuffer.substring(newCursor + (sizeReduced ? -1 : 0) - cursorStart).trim(); + int sizedReducedAdj = sizeReduced ? -1 : 0; + int begin = newCursor + sizedReducedAdj - cursorStart; + subString = remainingBuffer.substring(begin).trim(); } - // Exception handling - if (coe != null && newCursor < cursor && completionCandidates.size() == 0 && !(PreprocessorUtils.containsOnlyWhiteSpaces(subString) || ((subString - .endsWith(SyntaxConstants.LONG_OPTION_SPECIFIER) && subString - .startsWith(SyntaxConstants.LONG_OPTION_SPECIFIER)) || (subString - .startsWith(SyntaxConstants.SHORT_OPTION_SPECIFIER) && subString - .endsWith(SyntaxConstants.SHORT_OPTION_SPECIFIER))))) { + if (coe != null // hasException + && newCursor < cursor // newCursorIsEarlierThanCursor + && completionCandidates.size() == 0 // zeroCompletionCandidates + &&!(PreprocessorUtils.containsOnlyWhiteSpaces(subString) // onlyHasWhiteSpaces + || ((subString.endsWith(SyntaxConstants.LONG_OPTION_SPECIFIER) && subString.startsWith(SyntaxConstants.LONG_OPTION_SPECIFIER)) // isHypenHyphen + || (subString.startsWith(SyntaxConstants.SHORT_OPTION_SPECIFIER) && subString.endsWith(SyntaxConstants.SHORT_OPTION_SPECIFIER))))) { // isHyphen + ExceptionHandler.handleException(coe); return cursor; }
