Thank you for this awesome software! :)
We built a cli tool to help us install, build, and run our applications. We are now trying to capture analytics about how this tool is being used by developers:
For this, we would like to log data on every command. To do this, we would need to execute a function in every handler. There are two main issues we are facing:
Some work has already been done in this direction but for an individual command ( see @Khaledgarbaya PR https://github.com/yargs/yargs/pull/881 ).
A suggested solution is to add a yargs.middleware method which accepts a single callback or a list of callbacks. The method will extend the list of middleware passed on to each command ( see PR https://github.com/yargs/yargs/pull/1109 ).
Any feedback would be much appreciated.
Published this feature to npm with public access under @aorinevo/yargs.
npm install @aorinevo/yargs
const someMiddlewareFunc = argv => console.log('I\'m a middelware function: ', argv);
const someOtherMiddlewareFunc = argv => console.log('I\'m some other middelware function: ', argv);
module.exports = require('@aorinevo/yargs')
.middleware([someMiddlewareFunc, someOtherMiddlewareFunc]).argv;
On each cli command, someMiddlewareFunc and someOtherMiddlewareFunc get called first - in the order in which they appear, then any command level middleware, and finally the handler for the command.
just landed this feature request, great work @aorinevo.
So Late to the party OMG this amazing, Thanks @aorinevo
Most helpful comment
Published this feature to npm with public access under
@aorinevo/yargs.Install
Example
On each cli command, someMiddlewareFunc and someOtherMiddlewareFunc get called first - in the order in which they appear, then any command level middleware, and finally the handler for the command.