@@ -234,9 +234,9 @@ def __init__(self, completer, model_completer, docs,
234
234
self ._dot_cmd = DotCommandHandler ()
235
235
self ._env = os .environ .copy ()
236
236
self ._profile = None
237
- self .prompt_tokens = u'aws> '
238
237
self ._input = input
239
238
self ._output = output
239
+ self .prompt_tokens = u'aws > '
240
240
241
241
# These attrs come from the config file.
242
242
self .config_obj = None
@@ -272,6 +272,22 @@ def save_config(self):
272
272
self .config_section ['theme' ] = self .theme
273
273
self .config_obj .write ()
274
274
275
+ def add_context (self , text ):
276
+ self .model_completer .context .append (
277
+ text .split ()[0 ].strip ('@' ))
278
+ self .model_completer .reset ()
279
+ self .prompt_tokens = u'aws ' + ' ' .join (
280
+ self .model_completer .context ) + u' > '
281
+ self .refresh_cli = True
282
+ self .cli .request_redraw ()
283
+
284
+ def remove_context (self ):
285
+ self .model_completer .context .pop ()
286
+ self .prompt_tokens = u'aws ' + ' ' .join (
287
+ self .model_completer .context ) + u' > '
288
+ self .refresh_cli = True
289
+ self .cli .request_redraw ()
290
+
275
291
@property
276
292
def cli (self ):
277
293
if self ._cli is None or self .refresh_cli :
@@ -283,45 +299,39 @@ def run(self):
283
299
while True :
284
300
try :
285
301
document = self .cli .run (reset_current_buffer = True )
286
- if self .model_completer .context and isinstance (self .model_completer .context , list ):
287
- text = " " .join (self .model_completer .context ) + " " + document .text
302
+ if self .model_completer .context and isinstance (
303
+ self .model_completer .context , list ):
304
+ text = " " .join (self .model_completer .context ) + \
305
+ " " + document .text
306
+ original_text = document .text
288
307
else :
289
308
text = document .text
309
+ original_text = text
290
310
except InputInterrupt :
291
311
pass
292
312
except (KeyboardInterrupt , EOFError ):
293
313
self .save_config ()
294
314
break
295
315
else :
296
- if text .startswith ('.' ):
316
+ if original_text .startswith ('.' ):
297
317
# These are special commands (dot commands) that are
298
318
# interpreted by the aws-shell directly and typically used
299
319
# to modify some type of behavior in the aws-shell.
300
320
result = self ._dot_cmd .handle_cmd (text , application = self )
301
321
if result is EXIT_REQUESTED :
302
322
break
303
323
else :
304
- if text .startswith ('!' ):
305
- # Then run the rest as a normally shell command.
324
+ if original_text .startswith ('!' ):
325
+ # Then run the rest as a normal shell command.
306
326
full_cmd = text [1 :]
307
- elif text .startswith ('@' ) and len ( text . split ()) == 1 :
327
+ elif original_text .startswith ('@' ):
308
328
# Add word as context to completions
309
- self .model_completer .context .append (text .split ()[0 ].strip ('@' ))
310
- self .model_completer .reset ()
311
- self .prompt_tokens = u'aws ' + ' ' .join (self .model_completer .context ) + u' > '
312
- self .refresh_cli = True
313
- self .cli .request_redraw ()
329
+ self .add_context (text )
314
330
continue
315
- elif 'exit' in text .split ():
331
+ elif original_text == 'exit' and \
332
+ self .model_completer .context :
316
333
# Remove most recently added context
317
- if self .model_completer .context :
318
- self .model_completer .context .pop ()
319
- if self .model_completer .context :
320
- self .prompt_tokens = u'aws ' + ' ' .join (self .model_completer .context ) + u' > '
321
- else :
322
- self .prompt_tokens = u'aws > '
323
- self .refresh_cli = True
324
- self .cli .request_redraw ()
334
+ self .remove_context ()
325
335
continue
326
336
else :
327
337
full_cmd = 'aws ' + text
0 commit comments