({ schema, command, options, versions })
| 10 | } |
| 11 | |
| 12 | const validateCliSchema = async ({ schema, command, options, versions }) => { |
| 13 | const argv = buildArgvArray({ |
| 14 | command, |
| 15 | options, |
| 16 | }) |
| 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 | |
| 49 | cli.help('help').version(false).fail(false).wrap(null) |
| 50 | |
| 51 | const logger = log.get('core:version') |
| 52 | |
| 53 | if (command[0] === 'help' || options.help || options.h) { |
| 54 | logger.logo({ postfix: versions.serverless_framework }) |
| 55 | progress.get('main').remove() |
| 56 | cli.showHelp((s) => writeText(s)) |
| 57 | return { helpPrinted: true } |
| 58 | } |
| 59 | |
| 60 | if ( |
| 61 | command[0] === 'version' || |
| 62 | (command?.length === 0 && (options.version || options.v)) |
| 63 | ) { |
| 64 | logger.logo({ postfix: versions.serverless_framework }) |
| 65 | return { versionPrinted: true } |
| 66 | } |
| 67 | try { |
| 68 | const argv = cli.argv |
| 69 | const { command, options } = extractCommandsAndOptions(argv) |
no test coverage detected
searching dependent graphs…