-
Notifications
You must be signed in to change notification settings - Fork 124
Refactor exit_code implementation #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
cmd2.Cmd.cmdloop() now returns self.exit_code which should be an integer Also: - Refactored examples to call sys.exit(app.cmdloop()) in their __main__ - Running transcript tests now sets the exit_code accordingly based on success/failure - Updated CHANGELOG - Updated README - Updated Sphinx docs - Added unit test for case when transcript test fails
Codecov Report
@@ Coverage Diff @@
## master #685 +/- ##
==========================================
+ Coverage 95.28% 95.29% +0.01%
==========================================
Files 11 11
Lines 3181 3191 +10
==========================================
+ Hits 3031 3041 +10
Misses 150 150
Continue to review full report at Codecov.
|
|
is there a way to know if we are in transcript testing mode ? Should I test this PR ? I wonder if it will collide with this PR. |
|
@teto It would be a good idea for you to test this PR since it will affect your application. You will probably need to change your override slightly to be something like this: def cmdloop(self, intro=None):
"""
overrides baseclass just to be able to catch exceptions
"""
sys_exit_code = 0
try:
sys_exit_code = super().cmdloop()
except KeyboardInterrupt as e:
pass
# Exception raised by sys.exit(), which is called by argparse
# we don't want the program to finish just when there is an input error
except SystemExit as e:
sys_exit_code = self.cmdloop()
except mp.MpTcpException as e:
print(e)
sys_exit_code = self.cmdloop()
except Exception as e:
log.critical("Unknown error, aborting...")
log.critical("%s" % e)
print("Displaying backtrace:\n")
traceback.print_exc()
return sys_exit_codeAnd then in your outer sys.exit(app.cmdloop())Also, I'm curious why you are catching this exception: |
…isn't printed in failure cases
|
I'm going to go ahead and merge this. But please feel free to provide comments, I'd be happy to revise after the fact. |
cmd2.Cmd.cmdloop()now returnsself.exit_codewhich should be an integerAlso:
sys.exit(app.cmdloop())in their__main__exit_codeaccordingly based on success/failureCloses #682
Closes #684