MCPcopy
hub / github.com/serverless/serverless / validateCliSchema

Function validateCliSchema

packages/sf-core/src/utils/cli/cli.js:12–77  ·  view source on GitHub ↗
({ schema, command, options, versions })

Source from the content-addressed store, hash-verified

10}
11
12const 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)

Callers 2

routeFunction · 0.90
cli.test.jsFile · 0.85

Calls 8

writeTextFunction · 0.90
buildArgvArrayFunction · 0.85
applyConfigurationsFunction · 0.85
failMethod · 0.80
logoMethod · 0.80
getMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…