Conversation
|
This is a good idea...we had to implement this outside of cobra (which is fine.) But I think this establishes a good practice that all CLI's should have OOB. Some lint issues to clean up, at a quick glance it should be safe to annotate out |
|
@decanus Sorry for the delay. Can you rebase this to make CI pass? |
|
@marckhouzam done! |
marckhouzam
left a comment
There was a problem hiding this comment.
This is really great @decanus ! I love it!
I would like to include it in the next release of Cobra.
Would you be able to add a small paragraph of documentation after this section https://github.com/spf13/cobra/blob/main/site/content/user_guide.md#prerun-and-postrun-hooks
And a unit test would be important to make sure this does not break in the future.
Finally, there are a couple of linter errors to fix.
Thanks a lot!
|
I was thinking about how this new feature would be used. I like the fact that the Would that be a likely scenario? |
|
@decanus Are you still interested in getting this merged? |
| syscall.SIGINT, | ||
| syscall.SIGKILL, | ||
| syscall.SIGTERM, | ||
| syscall.SIGQUIT, |
There was a problem hiding this comment.
I think we also need os.Interrupt for things to work on Windows
There was a problem hiding this comment.
They seem to be supported for Windows, yet use of syscall package can be tricky for cross-platform Go.
/usr/lib/go/src/syscall/types_windows.go
|
found this through google - would be nice to get this finished and merged, but i guess for now i'll have to roll my own signal handler |
|
I'm still interested in merging this @decanus but CI is failing. |
A helper to run a function if a command is killed.