Skip to content

darlanmendonca/shell-arguments

Repository files navigation

Build Status Coverage Status npm version MIT Licence

shell-arguments

This module serialize the arguments passed to the npm, node, nodemon, forever, or pm2, and convert this arguments to json.

Install

npm install --save shell-arguments

and in your .js file

import args from 'shell-arguments';

console.log(args);

now, var args, return a object, with your data, example:

node app.js -b --test
=> {b: true, test: true}

If you want apply false, use

node app.js -b=false --test="false"
=> {b: false, test: false}

Note that the string with false value was converted to a boolean false, because this module convert primitive values.

Too accept other values, like below:

node app.js -o '/Desktop/teste' --output="/Desktop/teste"
=> {o: '/Desktop/teste', output: '/Desktop/teste'}

Convert primitive values

node app.js --port 8080 --numbers="2", --allow="false" --private="true"
=> {port: 8080, numbers: 2, allow: false, private: true}

Multiple flags with a single -, example:

node app.js -rpqs
=> {r: true, p: true, q: true, s: true}

Apply value with =, or space:

node app.js --output '/Desktop/test' --config="test"
=> {output: '/Desktop/test', config: 'test'}

About

Convert shell arguments to json

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published