Skip to content
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

Pre-exit cleanup callback #137

Open
ksiegel opened this issue Mar 22, 2016 · 6 comments
Open

Pre-exit cleanup callback #137

ksiegel opened this issue Mar 22, 2016 · 6 comments

Comments

@ksiegel
Copy link

ksiegel commented Mar 22, 2016

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
Copy link

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
Copy link

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
Copy link

soletan commented Jan 1, 2017

+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
Copy link

Any chance this will be implemented?

@slinkardbrandon
Copy link

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
Copy link

event vorpal.on('vorpal_exit') 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants