From 503845b758ad51085319c491cf2c9367542ef1f9 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Fri, 20 Apr 2018 05:11:06 +0530 Subject: [PATCH] updated readme with custom event listeners --- Readme.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Readme.md b/Readme.md index a29da4013..49b935881 100644 --- a/Readme.md +++ b/Readme.md @@ -356,6 +356,22 @@ function make_red(txt) { Output help information and exit immediately. Optional callback cb allows post-processing of help text before it is displayed. + +## Custom event listeners + You can execute custom actions by listening to command and option events. + +```js +program.on('option:verbose', function () { + process.env.VERBOSE = this.verbose; +}); + +// error on unknown commands +program.on('command:*', function () { + console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' ')); + process.exit(1); +}); +``` + ## Examples ```js