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

Parse multiple commands without exiting the process #934

Closed
Tanja-4732 opened this issue Mar 19, 2019 · 5 comments
Closed

Parse multiple commands without exiting the process #934

Tanja-4732 opened this issue Mar 19, 2019 · 5 comments
Milestone

Comments

@Tanja-4732
Copy link

Tanja-4732 commented Mar 19, 2019

Goals

  • Parse a final (immutable) string and take action accordingly
  • Keep the process open (including on -h and -v, and even on incorrect input)
  • Use commander.js as a library (will get called sometimes later, triggered by events)

Edit:

Goals continuation:

  • Get the output from -v and -h into a string instead of into the terminal

Use case

A bot which should listen for new messages in a live-chat channel.
Upon the arrival of a new message, it will look for a specific prefix, then send the command to commander.js to be parsed, and will take action accordingly.

Notice: The bot itself runs on a server in an automated manner and doesn't need nor expect any command-line arguments. The goal here is to parse several commands without the node process exiting because commander.js feels like it.

When a prefix -v comes along, it should respond. And it does - great!
But now my bot has made a clean exit.
Turns out commander.js decides when my app is done executing.

This behaviour is, of course, unacceptable, as the next user typing prefix -v into the chat will wait forever, for the bot is now shut down.

The fact that the bot needs to be reconnected to the chat-API and a database every time it starts doesn't make this situation easier.

TL;DR

How does one parse multiple commands without having their app shut down in between?
How to get the output from -v and -h into a string instead of into the terminal?


PS: #443 Talks about something somewhat-related

@shadowspawn
Copy link
Collaborator

Thanks for the use case, and for the succinct TL;DR too.

Related open issues about not calling exit: #443 #575

And issues about allowing custom exit code, so similar but different use case: #188 #435

@shadowspawn
Copy link
Collaborator

I have started work on an exit override: #945 (comment)

@shadowspawn
Copy link
Collaborator

There are improvements on the develop branch for the next release (#1040).

@shadowspawn
Copy link
Collaborator

v4.0.0-0 prerelease published: #1067

@shadowspawn
Copy link
Collaborator

v4.0.0 has been released.

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

No branches or pull requests

2 participants