Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chronologos committed Aug 5, 2016
1 parent 487c5c9 commit eed78f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
52 changes: 31 additions & 21 deletions awsshell/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ def __init__(self, completer, model_completer, docs,
self._dot_cmd = DotCommandHandler()
self._env = os.environ.copy()
self._profile = None
self.prompt_tokens = u'aws> '
self._input = input
self._output = output
self.prompt_tokens = u'aws > '

# These attrs come from the config file.
self.config_obj = None
Expand Down Expand Up @@ -272,6 +272,22 @@ def save_config(self):
self.config_section['theme'] = self.theme
self.config_obj.write()

def add_context(self, text):
self.model_completer.context.append(
text.split()[0].strip('@'))
self.model_completer.reset()
self.prompt_tokens = u'aws ' + ' '.join(
self.model_completer.context) + u' > '
self.refresh_cli = True
self.cli.request_redraw()

def remove_context(self):
self.model_completer.context.pop()
self.prompt_tokens = u'aws ' + ' '.join(
self.model_completer.context) + u' > '
self.refresh_cli = True
self.cli.request_redraw()

@property
def cli(self):
if self._cli is None or self.refresh_cli:
Expand All @@ -283,45 +299,39 @@ def run(self):
while True:
try:
document = self.cli.run(reset_current_buffer=True)
if self.model_completer.context and isinstance(self.model_completer.context, list):
text = " ".join(self.model_completer.context) + " " + document.text
if self.model_completer.context and isinstance(
self.model_completer.context, list):
text = " ".join(self.model_completer.context) + \
" " + document.text
original_text = document.text
else:
text = document.text
original_text = text
except InputInterrupt:
pass
except (KeyboardInterrupt, EOFError):
self.save_config()
break
else:
if text.startswith('.'):
if original_text.startswith('.'):
# These are special commands (dot commands) that are
# interpreted by the aws-shell directly and typically used
# to modify some type of behavior in the aws-shell.
result = self._dot_cmd.handle_cmd(text, application=self)
if result is EXIT_REQUESTED:
break
else:
if text.startswith('!'):
# Then run the rest as a normally shell command.
if original_text.startswith('!'):
# Then run the rest as a normal shell command.
full_cmd = text[1:]
elif text.startswith('@') and len(text.split()) == 1:
elif original_text.startswith('@'):
# Add word as context to completions
self.model_completer.context.append(text.split()[0].strip('@'))
self.model_completer.reset()
self.prompt_tokens = u'aws ' + ' '.join(self.model_completer.context) + u' > '
self.refresh_cli = True
self.cli.request_redraw()
self.add_context(text)
continue
elif 'exit' in text.split():
elif original_text == 'exit' and\
self.model_completer.context:
# Remove most recently added context
if self.model_completer.context:
self.model_completer.context.pop()
if self.model_completer.context:
self.prompt_tokens = u'aws ' + ' '.join(self.model_completer.context) + u' > '
else:
self.prompt_tokens = u'aws > '
self.refresh_cli = True
self.cli.request_redraw()
self.remove_context()
continue
else:
full_cmd = 'aws ' + text
Expand Down
7 changes: 4 additions & 3 deletions awsshell/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def autocomplete(self, line):
return self._handle_backspace()
elif not line:
return []
elif self._last_position == 0 and current_length > 2:
return self._complete_from_full_parse()
elif current_length != self._last_position + 1 and '--' in line:
elif (self._last_position == 0 and
current_length > 2) or (
current_length != self._last_position + 1
and '--' in line):
return self._complete_from_full_parse()

# This position is important. We only update the _last_position
Expand Down

0 comments on commit eed78f8

Please sign in to comment.