MCPcopy
hub / github.com/serverless/serverless / commandExist

Function commandExist

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

Source from the content-addressed store, hash-verified

77}
78
79const commandExist = ({ command, schema }) => {
80 const commandString = command.join(' ') // Combine the command parts into a single string
81
82 // Recursive helper function to check commands
83 const checkCommand = (schema, baseCommand = '') => {
84 for (const item of schema) {
85 const fullCommand = baseCommand
86 ? `${baseCommand} ${item.command}`.trim()
87 : item.command
88
89 if (fullCommand === commandString) {
90 return true // Exact match found
91 }
92
93 // Check nested commands if they exist
94 if (item.builder) {
95 const nestedCheck = checkCommand(item.builder, fullCommand)
96 if (nestedCheck) {
97 return true
98 }
99 }
100 }
101 return false // Command not found
102 }
103
104 return checkCommand(schema)
105}
106
107/**
108 * Get "command" and "options" from argv

Callers 2

getRunnerFunction · 0.90
cli.test.jsFile · 0.85

Calls 1

checkCommandFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…