2929
3030
3131LOG = logging .getLogger (__name__ )
32+ EXIT_REQUESTED = object ()
3233
3334
3435def create_aws_shell (completer , model_completer , docs ):
@@ -135,11 +136,18 @@ def run(self, command, application):
135136 self ._err .write ("Usage:\n %s\n " % self .USAGE )
136137
137138
139+ class ExitHandler (object ):
140+ def run (self , command , application ):
141+ return EXIT_REQUESTED
142+
143+
138144class DotCommandHandler (object ):
139145 HANDLER_CLASSES = {
140146 'edit' : EditHandler ,
141147 'profile' : ProfileHandler ,
142148 'cd' : ChangeDirHandler ,
149+ 'exit' : ExitHandler ,
150+ 'quit' : ExitHandler ,
143151 }
144152
145153 def __init__ (self , output = sys .stdout , err = sys .stderr ):
@@ -164,7 +172,7 @@ def handle_cmd(self, command, application):
164172 else :
165173 # Note we expect the class to support no-arg
166174 # instantiation.
167- self .HANDLER_CLASSES [cmd_name ]().run (parts , application )
175+ return self .HANDLER_CLASSES [cmd_name ]().run (parts , application )
168176
169177 def _unknown_cmd (self , cmd_parts , application ):
170178 self ._err .write ("Unknown dot command: %s\n " % cmd_parts [0 ])
@@ -272,12 +280,13 @@ def run(self):
272280 self .save_config ()
273281 break
274282 else :
275- if text .strip () in ['quit' , 'exit' ]:
276- break
277283 if text .startswith ('.' ):
278- # These are special commands. The only one supported for
279- # now is .edit.
280- self ._dot_cmd .handle_cmd (text , application = self )
284+ # These are special commands (dot commands) that are
285+ # interpreted by the aws-shell directly and typically used
286+ # to modify some type of behavior in the aws-shell.
287+ result = self ._dot_cmd .handle_cmd (text , application = self )
288+ if result is EXIT_REQUESTED :
289+ break
281290 else :
282291 if text .startswith ('!' ):
283292 # Then run the rest as a normally shell command.
0 commit comments