execa-output
v2.0.0
Published
A utility to display command output when using execa with listr.
Downloads
25
Maintainers
Readme
execa-output
A utility to display command output when using execa with listr.
execa-output
is responsible for creating the output sub text, like → text
, as seen in the screenshot below.
Install
NPM
$ npm i execa-output
Yarn
$ yarn add execa-output
Usage
Basic usage is exactly the same as using execa
.
const execa = require('execa');
const execao = require('execa-output');
const Listr = require('listr');
const tasks = new Listr([
{
task: () => execa('some', ['command']),
title: 'Comamnd without output or output you do not care to show'
},
{
task: () => execao('some', ['other', 'command']),
title: 'Command with output you want to show'
}
]);
tasks.run().catch((error) => {
console.error(error);
});
You can also pass in options to execa
, just like when using execa
directly.
const execao = require('execa-output');
const options = {};
execao('some', ['command'], options);
Lastly, you can also provide a callback when you need access to the commnand output.
const execao = require('execa-output');
execao('some', ['command'], null, (result) => {
console.log('command output:', value);
});
Credit
I use np to release npm packages and I have always :heart: it's simple, elegant presentation. It's how I learned about execa and listr, which I now use to build a lot of my own, custom npm scripts.
There's an issue on listr where people wanted to know how to display long running task output and it was recommended that one could reimplement / resue the code np uses.
This is exactly why execa-output
was created.
All credit for this code goes to @sindresorhus and @SamVerschueren for the original implementation. :pray:
I simply modularized it for reuse.
License
MIT © Michael Novotny