Closed jaraco closed 1 year ago
While definitely would not want to make this the default behavior, I'd be happy to add a new decorator, and add a matching flag to the autocommand decorator.
In jaraco.context 4.2, I added the on_interrupt decorator, which could be used in conjunction with autocommand:
@autocommand.autocommand(__name__)
@jaraco.context.on_interrupt('error')
def main(...):
...
It also could be used with other CLI entry points (abseil, simple).
Feel free to lift the implementation (or something similar) into autocommand, but for my purposes, I'll probably just use it from jaraco.context.
I was actually curious if there was a third party library that handles this separately, and probably more featurefully than we could do here. Glad you found one!
Currently, if one creates a command in Python and one interrupts it with Ctrl+C, it prints a full traceback and exits with a status 1.
I'm inclined to think autocommand/automain should either always trap KeyboardInterrupt exceptions or offer an option/decorator to trap exceptions, e.g.:
As I think about it, other commands on interrupt will typically not render a traceback but will exit with a non-zero status.
So perhaps that's the functionality that autocommand.trap_interrupt should do.
I don't feel strongly about any of these ideas, but I thought I'd start the discussion to see what others recommend.