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

Function getZshCompletions

packages/cli/src/internal/args.ts:1074–1114  ·  view source on GitHub ↗
(
  self: Instruction,
  state: ZshCompletionState = { multiple: false, optional: false }
)

Source from the content-addressed store, hash-verified

1072}
1073
1074export const getZshCompletions = (
1075 self: Instruction,
1076 state: ZshCompletionState = { multiple: false, optional: false }
1077): Array<string> => {
1078 switch (self._tag) {
1079 case "Empty": {
1080 return Arr.empty()
1081 }
1082 case "Single": {
1083 const multiple = state.multiple ? "*" : ""
1084 const optional = state.optional ? "::" : ":"
1085 const shortDescription = getShortDescription(self)
1086 const description = shortDescription.length > 0
1087 ? ` -- ${InternalCompletion.escapeSingleQuoted(shortDescription)}`
1088 : ""
1089 const possibleValues = InternalPrimitive.getZshCompletions(
1090 self.primitiveType as InternalPrimitive.Instruction
1091 )
1092 return possibleValues.length === 0
1093 ? Arr.empty()
1094 : Arr.of(`${multiple}${optional}${self.name}${description}${possibleValues}`)
1095 }
1096 case "Map": {
1097 return getZshCompletions(self.args as Instruction, state)
1098 }
1099 case "Both": {
1100 const left = getZshCompletions(self.left as Instruction, state)
1101 const right = getZshCompletions(self.right as Instruction, state)
1102 return Arr.appendAll(left, right)
1103 }
1104 case "Variadic": {
1105 return Option.isSome(self.max) && self.max.value > 1
1106 ? getZshCompletions(self.args as Instruction, { ...state, multiple: true })
1107 : getZshCompletions(self.args as Instruction, state)
1108 }
1109 case "WithDefault":
1110 case "WithFallbackConfig": {
1111 return getZshCompletions(self.args as Instruction, { ...state, optional: true })
1112 }
1113 }
1114}

Callers

nothing calls this directly

Calls 2

getShortDescriptionFunction · 0.70
ofMethod · 0.65

Tested by

no test coverage detected