Reads command arguments and gives a representative object of them
npm install reargvReads command-line arguments and returns a structured, representative object.
> Note: This module is intended to provide a lightweight alternative to full-featured argument management libraries such as commander.js.
> If you need a more fine-tuned or advanced CLI utility, consider using those instead of reargv.
``bash`
$ npm install reargv
First, create a script file somewhere
`js
//argv.mjs
import { reargv } from "reargv";
console.log(JSON.stringify(reargv(), null, 2))
`
Then, run it and pass it commands
`bash`
$ node ./argv.mjs hello --world reargv on.npm --and='this is great!' help VERSION -k8 -x > output.json
to output in output.json)`js
{
options: {
world: 'reargv',
and: '"this is great!"',
help: true,
version: true,
k: '8',
x: true
},
files: [ 'on.npm' ],
misc: [ 'hello' ]
}
`---
$3
`js
import { reargv } from "reargv";// Example:
process.argv = [
null,
null,
...[
"hello",
"--world",
"reargv",
"on.npm",
'--and="this is great!"',
"help",
"VERSION",
"-k8",
"-x",
],
];
const argv = reargv();
console.log(argv);
`$3
`js
{
options: {
world: 'reargv',
and: '"this is great!"',
help: true,
version: true,
k: '8',
x: true
},
files: [ 'on.npm' ],
misc: [ 'hello' ]
}
`---
API
$3
| Parameters | Returns |
|-----------|---------|
| / | A structured description of the command-line arguments |
$3
- options — An object containing arguments introduced by dashes (
- or --`) or matched special arguments.---