|
2 | 2 |
|
3 | 3 | JSON configurable command-line options parser
|
4 | 4 |
|
5 |
| -3.x Under developing... not tested yet |
| 5 | +3.x Under developing... not tested yet |
| 6 | + |
| 7 | +```javascript |
| 8 | +/** |
| 9 | + * @typedef {string} VarKey Variable name |
| 10 | + * @typedef {string | boolean | string[]} VarVal Variable value |
| 11 | + * @typedef {string} OptStr Option string, e.g. '--', '-o', '--option' |
| 12 | + * @typedef {OptStr | null} OptDef Option definitions, e.g. '--', '-o', '--option', or `null` to refer to the variable name |
| 13 | + * @typedef {OptDef | OptDef[]} OptKit one or more option definitions |
| 14 | + * |
| 15 | + * @typedef {object} VarKit Variable configuration object |
| 16 | + * @property {VarVal} def Variable **def**inition & **def**ault value (pun intended) |
| 17 | + * @property {OptKit} [set] Array of options to set the variable value |
| 18 | + * @property {OptKit} [rst] Array of options to reset the variable value |
| 19 | + * |
| 20 | + * @typedef {OptKit} HaltKit Halt options, identical to `OptKit`, for now... |
| 21 | + * @typedef {{opt: OptStr, key: VarKey}} HaltRes |
| 22 | + * @typedef {Record<VarKey, VarKit | HaltKit>} KeyKitMap |
| 23 | + * @typedef {Record<VarKey, VarVal>} KeyValMap |
| 24 | + * |
| 25 | + * @callback CanQuit |
| 26 | + * @param {{msg: string, i: number, opt: OptStr, key?: VarKey, val?: VarVal }} err |
| 27 | + * @returns {boolean} Whether the parsing should continue (false) or quit (true) |
| 28 | + * @typedef {Record<OptStr, VarKey>} OptKeyMap internal type |
| 29 | + */ |
| 30 | +/** |
| 31 | + * Command line argument parser function |
| 32 | + * @param {string[]} argv Command line arguments array |
| 33 | + * @param {number} i Index of current argument being processed |
| 34 | + * @param {KeyKitMap} req Options structure definition |
| 35 | + * @param {KeyValMap} res Object to store parsed results |
| 36 | + * @param {CanQuit} err Error handler function |
| 37 | + * @returns {{ i: number, halt?: HaltRes }} |
| 38 | + * @example |
| 39 | + */ |
| 40 | +export default function parse(argv, i, req, res, err); |
| 41 | +``` |
0 commit comments