@coder-ka/redargs
v1.0.3
Published
`redargs` is a minimal CLI arguments parser.
Downloads
3
Readme
redargs
redargs
is a minimal CLI arguments parser.
Installation
npm install redargs
Usage
"-"
is default flag name before some flag specified.
import { reduceArgs } from 'redargs';
// cli build --dist=dist -b
const parsed = reduceArgs<{
operation?: string;
dist: string;
}>(
process.argv.slice(2),
(parsed, flag) => {
switch (flag.name) {
case "-":
return {
...parsed,
operation: flag.values[0],
};
case "-d": // This is a way to define alias -d for --dist.
case "--dist":
return {
...parsed,
dist: flag.values[0],
};
default:
return parsed;
}
},
{
dist: 'dist'
}
);
console.log(parsed);
// Output: { operation: 'build', dist: 'dist' }