Socket
Socket
Sign inDemoInstall

argv-parse

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argv-parse

Parse command line arguments.


Version published
Weekly downloads
2K
increased by2.6%
Maintainers
1
Weekly downloads
 
Created
Source

argv-parse

npm travis standard

Parse command line arguments. This is a lot like yargs or optimist but not as feature rich.

You can specify flags, aliases, or not. Can pass arrays, strings, and booleans. No dependencies.

If you don't need array arguments, I'd recommend using minimist which is very good.

Install

npm install argv-parse

Usage

Say you had a file like foo-bar-qux.js which needed to parse arguments:

var argv = require('argv-parse')

// accepts a definition object and args
// if args is undefined, defaults to process.argv.slice(2)
var args = argv({
  foo: {
    type: 'boolean',
    alias: 'f'
  },
  bar: {
    type: 'string',
    alias: 'b'
  },
  qux: {
    type: 'array',
    alias: 'q'
  },
  norf: {
    type: 'boolean',
    alias: 'n'
  }
})
console.dir(args)
$ node foo-bar-qux.js --foo
{
  foo: true
}

$ node foo-bar-qux.js --bar hey
{
  bar: 'hey'
}

$ node foo-bar-qux.js --qux thing1 thing2 thing3
{
  qux: ['thing1', 'thing2', 'thing3']
}

$ node foo-bar-qux.js -f -b hey -q thing1 thing2 thing3
{
  foo: true,
  bar: 'hey',
  qux: ['thing1', 'thing2', 'thing3']
}

$ node foo-bar-qux.js -fn
{
  foo: true,
  norf: true
}

$ node foo-bar-qux.js not specified
{
  _: ['not', 'specified']
}

$ node foo-bar-qux.js --unknown surprise
{
  unknown: 'surprise'
}

If you don't care about aliases or types, you don't actually need to configure anything, argv-parse will intelligently guess how the unknown flag should be interpreted:

simple.js

var argv = require('argv-parse')
var args = argv()
console.dir(args)
$ node simple.js --unknown
{
  unknown: true
}

$ node simple.js --unknown hey
{
  unknown: 'hey'
}

$ node simple.js --unknown hey you
{
  unknown: ['hey', 'you']
}

$ node simple.js first second --unknown hey you
{
  _: ['first', 'second'],
  unknown: ['hey', 'you']
}

License

ISC

Keywords

FAQs

Package last updated on 07 Mar 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc