New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

simple-cli-parser

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-cli-parser

child_process via spawn parser, very simple.

1.0.1
latest
Source
npm
Version published
Weekly downloads
13
Maintainers
1
Weekly downloads
 
Created
Source

simple-cli-parser

Build Status

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!'); });

Keywords

cli

FAQs

Package last updated on 09 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts