@@ -185,6 +185,7 @@ def invoke(self, args, initial_invocation_data=None, out_file=None):
185
185
186
186
if not isinstance (args , (list , tuple )):
187
187
raise TypeError ('args should be a list or tuple.' )
188
+ exit_code = 0
188
189
try :
189
190
args = self .completion .get_completion_args () or args
190
191
out_file = out_file or self .out_file
@@ -195,6 +196,7 @@ def invoke(self, args, initial_invocation_data=None, out_file=None):
195
196
self .raise_event (EVENT_CLI_PRE_EXECUTE )
196
197
if CLI ._should_show_version (args ):
197
198
self .show_version ()
199
+ self .result = CommandResultItem (None )
198
200
else :
199
201
self .invocation = self .invocation_cls (cli_ctx = self ,
200
202
parser_cls = self .parser_cls ,
@@ -203,17 +205,19 @@ def invoke(self, args, initial_invocation_data=None, out_file=None):
203
205
initial_data = initial_invocation_data )
204
206
cmd_result = self .invocation .execute (args )
205
207
self .result = cmd_result
208
+ exit_code = self .result .exit_code
206
209
output_type = self .invocation .data ['output' ]
207
210
if cmd_result and cmd_result .result is not None :
208
211
formatter = self .output .get_formatter (output_type )
209
212
self .output .out (cmd_result , formatter = formatter , out_file = out_file )
210
213
self .raise_event (EVENT_CLI_POST_EXECUTE )
211
214
except KeyboardInterrupt as ex :
212
- self .result = CommandResultItem (None , exit_code = 1 , error = ex )
215
+ self .result = CommandResultItem (None , error = ex )
213
216
exit_code = 1
214
217
except Exception as ex : # pylint: disable=broad-except
215
218
exit_code = self .exception_handler (ex )
216
- self .result = CommandResultItem (None , exit_code = exit_code , error = ex )
219
+ self .result = CommandResultItem (None , error = ex )
217
220
finally :
218
221
pass
219
- return self .result .exit_code
222
+ self .result .exit_code = exit_code
223
+ return exit_code
0 commit comments