@anio-node-foundation/cli-parse-args
v3.0.0
Published
A pretty simple CLI args parser.
Downloads
531
Readme
@anio-node-foundation/cli-parse-args
Parses command line arguments.
import parseCLIArgs from "@anio-node-foundation/cli-parse-args"
const args = await parseCLIArgs(
process.argv.slice(2), {
flags: ["test"],
/* options are key-value based */
/* value specifies the type of value required */
// valid types:
// fs:file
// fs:dir
// fs:path
// string
// float
// integer
// "type" can also be a function that validates the value
options: {
"file": "fs:file",
"special-value": function(value) {
return `something-${value}`
}
},
// multi options means option can be specified more than one time
multi_options: ["file"]
}
)
console.log(
args
)
Invoking the script with, say ./example.mjs -test --file example.mjs --special-value a b c -- -test
Yields the following result:
{
flags: [ 'test' ],
operands: [ 'b', 'c', '-test' ],
options: {
file: '/absolute/path/to/example.mjs',
'special-value': 'something-a'
}
}