Merge remote-tracking branch 'origin/pr/3063'

This commit is contained in:
Florian Bruhin 2017-10-17 11:34:35 +02:00
commit c233099bca
3 changed files with 34 additions and 0 deletions

View File

@ -220,6 +220,8 @@ class CommandParser:
matches.append(valid_command)
if len(matches) == 1:
cmdstr = matches[0]
elif len(matches) > 1 and config.val.completion.use_best_match:
cmdstr = matches[0]
return cmdstr
def _split_args(self, cmd, argstr, keep):

View File

@ -692,6 +692,11 @@ completion.min_chars:
minval: 1
desc: Minimum amount of characters needed to update completions.
completion.use_best_match:
type: Bool
default: false
desc: Whether to execute the best-matching command on a partial match.
## downloads
downloads.location.directory:

View File

@ -74,3 +74,30 @@ class TestCommandParser:
parser = runners.CommandParser(partial_match=True)
result = parser.parse('message-i')
assert result.cmd.name == 'message-info'
class TestCompletions:
"""Tests for completions.use_best_match."""
def test_dont_use_best_match(self, config_stub):
"""Test multiple completion options with use_best_match set to false.
Should raise NoSuchCommandError
"""
config_stub.val.completion.use_best_match = False
parser = runners.CommandParser(partial_match=True)
with pytest.raises(cmdexc.NoSuchCommandError):
result = parser.parse('do')
def test_use_best_match(self, config_stub):
"""Test multiple completion options with use_best_match set to true.
The resulting command should be the best match
"""
config_stub.val.completion.use_best_match = True
parser = runners.CommandParser(partial_match=True)
result = parser.parse('do')
assert result.cmd.name == 'download-cancel'