simple-cli-parser
v1.0.1
Published
child_process via spawn parser, very simple.
Downloads
141
Maintainers
Readme
simple-cli-parser
A simple parser for a spawning child_process, with promises.
Install
npm install simple-cli-parser --save
Usage
To see the result of ls -la.
'use strict';
const cli = require('simple-cli-parser');
let ls = new cli([ 'ls', '-la', __dirname ])
.then(res => { console.log('Success!', res); })
.catch(err => { console.log('Failed!'); });
To stream the result of a curl download (to check current percentage).
'use strict';
const cli = require('simple-cli-parser'),
currentPercentage = data => { // Optional function for checking status
let percent = parseFloat(data, 10);
if (!isNaN(percent) && percent > 0){ console.log(percent + '%'); }
};
let download = new cli([ 'curl', '-O', 'http://speedtest.ftp.otenet.gr/files/test10Mb.db', '-#' ], currentPercentage)
.then(res => { console.log('Success!', res); })
.catch(err => { console.log('Failed!'); });
To pass options (https://nodejs.org/api/child_process.html)
'use strict';
const cli = require('simple-cli-parser');
let ls = new cli([ 'git', 'branch', '-a' ], null, { cwd: '/repos/app' })
.then(res => { console.log('Success!', res); })
.catch(err => { console.log('Failed!'); });