(cliInstance, schemaConfig)
| 17 | const cli = yargs(argv).scriptName('') |
| 18 | |
| 19 | const applyConfigurations = (cliInstance, schemaConfig) => { |
| 20 | schemaConfig.forEach((config) => { |
| 21 | // Handle commands with sub-configurations |
| 22 | if (config.command) { |
| 23 | cliInstance.command(config.command, config.description, (yargs) => { |
| 24 | // Recursively configure sub-commands or options if a builder is provided |
| 25 | if (config.builder) { |
| 26 | return applyConfigurations(yargs, config.builder) |
| 27 | } |
| 28 | return yargs |
| 29 | }) |
| 30 | } else { |
| 31 | // Dynamically apply configurations for options, positionals, etc. |
| 32 | Object.entries(config).forEach(([key, value]) => { |
| 33 | // check if the key is a function on the yargs instance |
| 34 | if (typeof cliInstance[key] === 'function') { |
| 35 | // If a value is an array, assume it's arguments for the yargs method |
| 36 | if (Array.isArray(value)) { |
| 37 | cliInstance[key](...value) |
| 38 | } else { |
| 39 | cliInstance[key](value) |
| 40 | } |
| 41 | } |
| 42 | }) |
| 43 | } |
| 44 | }) |
| 45 | } |
| 46 | |
| 47 | applyConfigurations(cli, schema) |
| 48 |
no outgoing calls
no test coverage detected
searching dependent graphs…