-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Make calls to process.exit() overridable #575
Description
In general, library code should never call process.exit(). Instead, clients of the library should decide how they want to handle errors.
In particular, tying process.exit(0) to --help seems particularly bad. For a CLI parser, this may be a reasonable default, but this behavior should at least be overridable.
I am trying to build a daemon running on a UNIX domain socket that takes requests and uses commander to parse arguments just as it would if it were running in non-daemon mode. Given the way commander works today, passing --help has the side-effect of tearing down my daemon.
I have similar issues where commander makes calls to process.stdout.write() that are writing to the "wrong" stdout, from my perspective. I think the best way to secure things as a library is to remove all direct references to process from index.js and make all of its behavior injectable. It can still default to what it does today, but it should be overridable.