Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clia

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clia

Command line parser and t3st example project

  • 2020.8.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
35
Maintainers
1
Weekly downloads
 
Created
Source

clia

Command line arguments parser and t3st example project

usage

In your-node-app:

const clia = require('clia')

const opts = clia(process.argv.slice(2))

From the command line input flags (abcd) and unflagged (hello)

node your-node-app -a -ab -cd hello

Yields

opts === {
    a: true,
    b: true,
    c: true,
    d: true
    $$: ['hello']
}

parlance - options and arguments

cli a -b c --d --e=f
a: argument (untagged)
b: option (short)
c: argument (tagged)
d: option (long)
e: option (key-value)
f: argument (key-value)

option -> boolean flag(s)

  • short option
    • starts with single -
    • refers to one or more options
  • long option
    • starts with double --
    • refers to one option
  • key-value option
    • the key in --key=value

argument -> character(s)

  • untagged:
    • argument(s) preceding any options
  • tagged
    • argument(s) succeeding the last short option or long option
  • key-value argument
    • the value in --key=value

parsing

  • When a key-value option is stated more than once, the last value is used assigned

errors are thrown for:

  • __proto__ to prevent prototype pollution
  • dangling -- argument (WIP -- will indicate all subsequent input to be treated as arguments)

testing

Clone and run tests:

git clone https://github.com/devmachiine/clia.git
cd clia
npm i # optional
npm i -g nodemon # optional
npm test

To run live (aka hot-reload) tests:

# ctrl+c to exit.
npm start 

references

The Art of Unix Programming

GNU argument syntax conventions

getopts (therefore this IEEE doc)

CI

License

Keywords

FAQs

Package last updated on 06 Aug 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

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