GithubHelp home page GithubHelp logo

pipe-args's Introduction

pipe-args

Build Status

pipe

pipe-args adds support for unix piped arguments to your node CLI apps

pipe-args makes your node CLI apps to fully support unix pipelines, completely out of the box. Require the the pipe-args module and all the piped arguments are added to the process stdin transparently. It also integrates well with popular command line interface/parsers like yarg and commander.js.

Installation

$ npm install --save pipe-args

Usage

#!/usr/bin/env node

const pipe = require('pipe-args').load();
console.log(`The piped arg is ${process.argv[2]}`);
$ echo test | node index.js

$ The piped arg is test

Options

You can define which commands allow the stdin to be copied to process.argv by passing them in the options object:

#!/usr/bin/env node

const pipe = require('pipe-args').load(['command']);
console.log(`The piped arg is ${process.argv[2]}`);
$ echo OK | node command index.js

$ The piped arg is OK
$ echo OK | node commandNotPiping index.js

$ The piped arg is null // stdin was not parsed into process.argv

Integrations

pipe-args plays along with optstrings parsers such as yarg. The following yargs parser code:

#!/usr/bin/env node

const pipe = require('pipe-args').load();
const yargs = require('yargs')

const cli = yargs.demand(1)

console.log(cli.argv);

parses linux-style piped arguments as expected:

$ echo piped_arg | yargs-cli.js

$ { _: [ 'piped_arg' ], '$0': 'index.js' }

License:

MIT © Gonçalo Pestana

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.