MCPcopy Create free account
hub / github.com/langgenius/dify / resolveCommand

Function resolveCommand

cli/src/framework/registry.ts:14–43  ·  view source on GitHub ↗
(
  tree: CommandTree,
  argv: string[],
)

Source from the content-addressed store, hash-verified

12}
13
14export function resolveCommand(
15 tree: CommandTree,
16 argv: string[],
17): { command: CommandConstructor, path: string[] } | undefined {
18 const path: string[] = []
19 let node: CommandNode | undefined
20 let lastMatch: { command: CommandConstructor, path: string[] } | undefined
21
22 for (let i = 0; i < argv.length; i++) {
23 const token = argv[i]
24 if (token === undefined || token.startsWith('-'))
25 break
26
27 const next = path.length === 0 ? tree[token] : node?.subcommands[token]
28 if (!next)
29 break
30
31 node = next
32 path.push(token)
33
34 if (node.command) {
35 lastMatch = { command: node.command, path: [...path] }
36 const nextToken = argv[i + 1]
37 if (nextToken === undefined || nextToken.startsWith('-') || !(nextToken in node.subcommands))
38 return lastMatch
39 }
40 }
41
42 return lastMatch
43}
44
45function editDistance(a: string, b: string): number {
46 const m = a.length

Callers 2

runFunction · 0.90
registry.test.tsFile · 0.90

Calls 2

startsWithMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected