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
argument -> character(s)
- untagged:
- argument(s) preceding any options
- tagged
- argument(s) succeeding the last short option or long option
- key-value argument
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
npm i -g nodemon
npm test
To run live (aka hot-reload) tests:
npm start
references
The Art of Unix Programming
GNU argument syntax conventions
getopts (therefore this IEEE doc)