MCPcopy Create free account
hub / github.com/Effect-TS/effect / buildSubcommandIndex

Function buildSubcommandIndex

packages/effect/src/cli/internal/parser.ts:279–302  ·  view source on GitHub ↗
(
  subcommands: Command.Any["subcommands"]
)

Source from the content-addressed store, hash-verified

277}
278
279const buildSubcommandIndex = (
280 subcommands: Command.Any["subcommands"]
281): Map<string, Command<string, unknown, unknown, unknown, unknown>> => {
282 const index = new Map<string, Command<string, unknown, unknown, unknown, unknown>>()
283 const setKey = (key: string, command: Command<string, unknown, unknown, unknown, unknown>) => {
284 const existing = index.get(key)
285 if (existing && existing !== command) {
286 throw new Error(
287 `Duplicate subcommand name/alias "${key}" in command definition (conflicts with "${existing.name}")`
288 )
289 }
290 index.set(key, command)
291 }
292
293 for (const group of subcommands) {
294 for (const subcommand of group.commands) {
295 setKey(subcommand.name, subcommand)
296 if (subcommand.alias && subcommand.alias !== subcommand.name) {
297 setKey(subcommand.alias, subcommand)
298 }
299 }
300 }
301 return index
302}
303
304/* ========================================================================== */
305/* Flag Accumulator */

Callers 2

consumeLevelFunction · 0.85
resolveFirstValueFunction · 0.85

Calls 1

setKeyFunction · 0.85

Tested by

no test coverage detected