clef-parse
The argv parser behind cleffa and clefairy.
Usage
As a node.js library
import { parseArgv } from "clef-parse";
const result = parseArgv([
"--bundle",
"--input",
"index.js",
"--output",
"bundle.js",
"-v",
]);
console.log(result);
const result2 = parseArgv(
["--bundle", "--input", "index.js", "--output", "bundle.js", "-v"],
{
bundle: Boolean,
input: String,
output: String,
v: Boolean,
}
);
console.log(result2);
import { Path } from "clef-parse";
const result3 = parseArgv(
["--bundle", "--input", "index.js", "--output", "bundle.js", "-v"],
{
bundle: Boolean,
input: Path,
output: Path,
v: Boolean,
}
);
console.log(result3);
See the TypeScript types in the source code for more information.
As a CLI tool
$ npm install -g clef-parse
$ clef-parse one two --three-four=five
{
"options": {
"threeFour": "five"
},
"positionalArgs": [
"one",
"two"
]
}
To specify hints with the CLI tool, use environment variables named like CLEF_PARSE_HINT_<option name goes here>
. For instance:
$ clef-parse some stuff --with-batteries yeah yup
{
"options": {
"withBatteries": "yeah"
},
"positionalArgs": [
"some",
"stuff",
"yup"
]
}
$ env CLEF_PARSE_HINT_WITH_BATTERIES=Boolean clef-parse some stuff --with-batteries yeah yup
{
"options": {
"withBatteries": true
},
"positionalArgs": [
"some",
"stuff",
"yeah",
"yup"
]
}
License
MIT