dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

Pre-exit cleanup callback #137

Open ksiegel opened 8 years ago

ksiegel commented 8 years ago

Really enjoying using Vorpal so far! Thank you guys for making such an awesome library happen.

One thing I'm trying to chase down is how to gracefully quit an app I'm working on. I'm emulating a virtual real-world device that does a thing on an interval. When I ctrl-c ctrl-c to exit that device, that interval keeps going and I'm forced to kill node directly as it keeps going forever. I'd like to be able to cancel that and any other async action that may be pending in an exit function.

I couldn't find any events to listen in to for this, and using the API for process itself seems a bit more haphazard than I'd like.

Any plans for this? Elegant workarounds?

steelbrain commented 8 years ago

I've partially done this by removing the existing exit command and adding my own, but having a built-in way to do this would be nice as we'll also be able to react to ctrl + c

avivbeeri commented 8 years ago

I'd really like this feature, especially as I use Vorpal to provide an interactive environment for managing a database. Being able to safely close a connection on exit or sigterm would be wonderful.

soletan commented 7 years ago

+1

I've checked the sources and find Vorpal API incomplete: Since vorpal.command() is always creating and registering another command there should be some option to access any previously registered command e.g. to remove it as advised in warning emitted on trying to re-register custom version of exit. That might help with replacing Vorpal common commands. Of course, there is vorpal.commands, but AFAIC accessing merely internal data structures of vorpal directly is like circumventing some clean API. What about vorpal.command( "exit" ) providing previously registered command?

Another advantage of re-accessing previously registered commands would be support for compiling custom commands using plugins and similar kinds of modules, even though this might require more efforts that probably aren't considerable part of vorpal as a lightweight core.

Finally, IMHO best solution would be to have some event emitted before exiting session when using vorpal's common implementation of exit command.

UPDATE: In addition to request of @steelbrain I'd love to have a CLI framework providing common hook for acting on exiting CLI application, that is using command exit or pressing Ctrl+C twice (obviously requiring monitoring of SIGINT event).

robert-e-davidson3 commented 5 years ago

Any chance this will be implemented?

slinkardbrandon commented 5 years ago

Unlikely unless you tackle it on your own. The primary vorpal repo is basically unmaintained at this point.

There is a “reforge” that’s going on here: https://github.com/vorpaljs-reforged/vorpal if you’re interested

FellipeP commented 2 years ago

event vorpal.on('vorpal_exit') 👍🏻