29
29
30
30
31
31
LOG = logging .getLogger (__name__ )
32
+ EXIT_REQUESTED = object ()
32
33
33
34
34
35
def create_aws_shell (completer , model_completer , docs ):
@@ -135,11 +136,18 @@ def run(self, command, application):
135
136
self ._err .write ("Usage:\n %s\n " % self .USAGE )
136
137
137
138
139
+ class ExitHandler (object ):
140
+ def run (self , command , application ):
141
+ return EXIT_REQUESTED
142
+
143
+
138
144
class DotCommandHandler (object ):
139
145
HANDLER_CLASSES = {
140
146
'edit' : EditHandler ,
141
147
'profile' : ProfileHandler ,
142
148
'cd' : ChangeDirHandler ,
149
+ 'exit' : ExitHandler ,
150
+ 'quit' : ExitHandler ,
143
151
}
144
152
145
153
def __init__ (self , output = sys .stdout , err = sys .stderr ):
@@ -164,7 +172,7 @@ def handle_cmd(self, command, application):
164
172
else :
165
173
# Note we expect the class to support no-arg
166
174
# instantiation.
167
- self .HANDLER_CLASSES [cmd_name ]().run (parts , application )
175
+ return self .HANDLER_CLASSES [cmd_name ]().run (parts , application )
168
176
169
177
def _unknown_cmd (self , cmd_parts , application ):
170
178
self ._err .write ("Unknown dot command: %s\n " % cmd_parts [0 ])
@@ -272,12 +280,13 @@ def run(self):
272
280
self .save_config ()
273
281
break
274
282
else :
275
- if text .strip () in ['quit' , 'exit' ]:
276
- break
277
283
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
281
290
else :
282
291
if text .startswith ('!' ):
283
292
# Then run the rest as a normally shell command.
0 commit comments