MCPcopy Index your code
hub / github.com/Effect-TS/effect / traverseCommand

Function traverseCommand

packages/cli/src/internal/commandDescriptor.ts:998–1048  ·  view source on GitHub ↗
(
  self: Instruction,
  initialState: S,
  f: (state: S, info: CommandInfo) => Effect.Effect<S>
)

Source from the content-addressed store, hash-verified

996 * based on information acquired from the command.
997 */
998const traverseCommand = <S>(
999 self: Instruction,
1000 initialState: S,
1001 f: (state: S, info: CommandInfo) => Effect.Effect<S>
1002): Effect.Effect<S> =>
1003 SynchronizedRef.make(initialState).pipe(Effect.flatMap((ref) => {
1004 const loop = (
1005 self: Instruction,
1006 parentCommands: ReadonlyArray<string>,
1007 subcommands: ReadonlyArray<[string, Standard | GetUserInput]>,
1008 level: number
1009 ): Effect.Effect<void, never, never> => {
1010 switch (self._tag) {
1011 case "Standard": {
1012 const info: CommandInfo = {
1013 command: self,
1014 parentCommands,
1015 subcommands,
1016 level
1017 }
1018 return SynchronizedRef.updateEffect(ref, (state) => f(state, info))
1019 }
1020 case "GetUserInput": {
1021 const info: CommandInfo = {
1022 command: self,
1023 parentCommands,
1024 subcommands,
1025 level
1026 }
1027 return SynchronizedRef.updateEffect(ref, (state) => f(state, info))
1028 }
1029 case "Map": {
1030 return loop(self.command, parentCommands, subcommands, level)
1031 }
1032 case "Subcommands": {
1033 const parentNames = getNamesInternal(self.parent)
1034 const nextSubcommands = getSubcommandsInternal(self)
1035 const nextParentCommands = Arr.appendAll(parentCommands, parentNames)
1036 // Traverse the parent command using old parent names and next subcommands
1037 return loop(self.parent, parentCommands, nextSubcommands, level).pipe(
1038 Effect.zipRight(Effect.forEach(self.children, (child) =>
1039 // Traverse the child command using next parent names and old subcommands
1040 loop(child, nextParentCommands, subcommands, level + 1)))
1041 )
1042 }
1043 }
1044 }
1045 return Effect.suspend(() => loop(self, Arr.empty(), Arr.empty(), 0)).pipe(
1046 Effect.zipRight(SynchronizedRef.get(ref))
1047 )
1048 }))
1049
1050const indentAll = dual<
1051 (indent: number) => (self: ReadonlyArray<string>) => Array<string>,

Callers 3

Calls 4

loopFunction · 0.70
pipeMethod · 0.65
makeMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected