It may sound a little weird to have to use this.context.stdout.write to write to the console in a Node context (developers are used to just call console.log for that). While it's important to keep this distinction in order to let commands be chainable (ie one command may call others and capture their output), newest Node releases may provide us an interesting tool to improve the user experience.
This diff introduces a new option, enableCapture. When set (the default is false at the moment), passing non-standard streams to a CLI execution will cause Clipanion to register itself into the process.stdout.write pipeline (same for stderr), effectively capturing everything that JS code would print. Asynchronicity shouldn't be an issue thanks to AsyncLocalStorage, which will ensure that each command access their own streams, even if asynchronous.
It may sound a little weird to have to use
this.context.stdout.write
to write to the console in a Node context (developers are used to just callconsole.log
for that). While it's important to keep this distinction in order to let commands be chainable (ie one command may call others and capture their output), newest Node releases may provide us an interesting tool to improve the user experience.This diff introduces a new option,
enableCapture
. When set (the default isfalse
at the moment), passing non-standard streams to a CLI execution will cause Clipanion to register itself into theprocess.stdout.write
pipeline (same for stderr), effectively capturing everything that JS code would print. Asynchronicity shouldn't be an issue thanks toAsyncLocalStorage
, which will ensure that each command access their own streams, even if asynchronous.