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

simple-args-parser

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

simple-args-parser

A simple parser for command line arguments (process.argv[])

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

simple-args-parser

Parse command line arguments (process.argv[]) in one function

Syntax:

args = parser.parse(process.argv, config, fallback?)

Config:

{
    short: [],
    long: [],
    stupid: [],
    errOnDisallowed: true
}

short[] is an array of short arguments (eg. -a)

long[] is an array of long arguments (eg. --long)

stupid[] is an array of stupid arguments (Long arguments with one -, eg -stupid)

If you want to get the argument parameter (--argument 'parameter'), add a : after the argument in the array

// Without argument
short: ['a']

// With argument
short: ['a:']

As you may have noticed, dont put the - with the argument into the array.

Fallback: Fallback is a function called when an error is recieved, called by fallback(err). If you dont specify a custon one, the error will be thrown upon encounter.

Example:

const parser = require('simple-args-parser')

args = parser.parse(process.argv, {
  short: ['a:', 'b:', 'c'],
  long: ['hello', 'world:'],
  stupid: ['powershell', 'bill:'],
  errOnDisallowed: true
}, (err) => {
  console.log(err)
})

console.log(args)

Try running this script like node test.js -a word -b 'this is a string' -c --hello --world indeed -powershell -bill 'gates'. It should output

{
  a: 'word',
  b: 'this is a string',
  c: true,
  hello: true,
  world: 'indeed',
  powershell: true,
  bill: 'gates'
}

Keywords

FAQs

Package last updated on 03 Feb 2021

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