Skip to content

Commit

Permalink
Fixed #14: Fuzzy completions are sometimes showing incorrect completi…
Browse files Browse the repository at this point in the history
…ons for built-in commands and subcommands. Added unit test to cover this bug and an entry in the manual test.
  • Loading branch information
donnemartin committed Sep 21, 2015
1 parent 800d8fb commit 79f3acf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Run the following on Python 2.7 and Python 3.4:
* Commands
* Blank
* aws
* aws elb
* aws s3api get-bucket-acl --bucket
* aws ec2 describe-instances --instance-ids
* aws ecls
Expand Down
13 changes: 12 additions & 1 deletion saws/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class AwsCompleter(Completer):

def __init__(self,
aws_completer,
commands,
config_obj,
log_exception,
ec2_states=[],
Expand All @@ -59,6 +60,7 @@ def __init__(self,
Args:
* aws_completer: The official aws cli completer module.
* commands: A list of AWS top-level commands such ec2, elb, s3, etc.
* config_obj: An instance of ConfigObj, reads from ~/.sawsrc.
* log_exception: A callable log_exception from SawsLogger.
* ec2_states: A list of the possible instance states.
Expand All @@ -71,6 +73,7 @@ def __init__(self,
None.
"""
self.aws_completer = aws_completer
self.commands = commands
self.aws_completions = set()
self.config_obj = config_obj
self.log_exception = log_exception
Expand Down Expand Up @@ -287,7 +290,15 @@ def get_completions(self, document, _):
completions = self.get_all_resource_completions(words,
word_before_cursor)
if completions is None:
fuzzy_aws_completions = self.fuzzy_match
if self.fuzzy_match and word_before_cursor in self.commands:
# Fuzzy completion currently only works with AWS resources
# and shortcuts. If we have just completed a top-level
# command (ie. ec2, elb, s3) then disable fuzzy completions,
# otherwise the corresponding subcommands will be fuzzy
# completed and incorrectly shown.
fuzzy_aws_completions = False
completions = self.text_utils.find_matches(word_before_cursor,
self.aws_completions,
fuzzy=False)
fuzzy_aws_completions)
return completions
1 change: 1 addition & 0 deletions saws/saws.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(self):
= self.aws_commands.generate_all_commands()
self.completer = AwsCompleter(
awscli_completer,
self.commands,
self.config_obj,
self.log_exception,
ec2_states=self.ec2_states,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def create_completer(self):
self.resource_options, self.ec2_states = \
self.aws_commands.generate_all_commands()
return AwsCompleter(awscli_completer,
self.saws.commands,
self.saws.config_obj,
self.saws.logger,
self.ec2_states)
Expand Down Expand Up @@ -72,6 +73,15 @@ def verify_completions(self, commands, expected):
for item in expected:
assert item in result_texts

def test_no_completions(self):
command = 'aws ec2'
expected = set([])
assert expected == self._get_completions(command)
command = 'aws elb'
assert expected == self._get_completions(command)
command = 'aws elasticache'
assert expected == self._get_completions(command)

def test_ec2_commands(self):
commands = ['aws e']
expected = ['ec2',
Expand Down

0 comments on commit 79f3acf

Please sign in to comment.