MCPcopy
hub / github.com/Effect-TS/effect / getZshCompletions

Function getZshCompletions

packages/cli/src/internal/options.ts:2164–2219  ·  view source on GitHub ↗
(
  self: Instruction,
  state: ZshCompletionState = { conflicts: Arr.empty(), multiple: false }
)

Source from the content-addressed store, hash-verified

2162
2163/** @internal */
2164export const getZshCompletions = (
2165 self: Instruction,
2166 state: ZshCompletionState = { conflicts: Arr.empty(), multiple: false }
2167): Array<string> => {
2168 switch (self._tag) {
2169 case "Empty": {
2170 return Arr.empty()
2171 }
2172 case "Single": {
2173 const names = getNames(self)
2174 const description = getShortDescription(self)
2175 const possibleValues = InternalPrimitive.getZshCompletions(
2176 self.primitiveType as InternalPrimitive.Instruction
2177 )
2178 const multiple = state.multiple ? "*" : ""
2179 const conflicts = Arr.isNonEmptyReadonlyArray(state.conflicts)
2180 ? `(${Arr.join(state.conflicts, " ")})`
2181 : ""
2182 return Arr.map(
2183 names,
2184 (name) => `${conflicts}${multiple}${name}[${escape(description)}]${possibleValues}`
2185 )
2186 }
2187 case "KeyValueMap": {
2188 return getZshCompletions(self.argumentOption as Instruction, { ...state, multiple: true })
2189 }
2190 case "Map":
2191 case "WithDefault":
2192 case "WithFallback": {
2193 return getZshCompletions(self.options as Instruction, state)
2194 }
2195 case "Both": {
2196 const left = getZshCompletions(self.left as Instruction, state)
2197 const right = getZshCompletions(self.right as Instruction, state)
2198 return Arr.appendAll(left, right)
2199 }
2200 case "OrElse": {
2201 const leftNames = getNames(self.left as Instruction)
2202 const rightNames = getNames(self.right as Instruction)
2203 const left = getZshCompletions(
2204 self.left as Instruction,
2205 { ...state, conflicts: Arr.appendAll(state.conflicts, rightNames) }
2206 )
2207 const right = getZshCompletions(
2208 self.right as Instruction,
2209 { ...state, conflicts: Arr.appendAll(state.conflicts, leftNames) }
2210 )
2211 return Arr.appendAll(left, right)
2212 }
2213 case "Variadic": {
2214 return Option.isSome(self.max) && self.max.value > 1
2215 ? getZshCompletions(self.argumentOption as Instruction, { ...state, multiple: true })
2216 : getZshCompletions(self.argumentOption as Instruction, state)
2217 }
2218 }
2219}

Callers

nothing calls this directly

Calls 5

getNamesFunction · 0.70
getShortDescriptionFunction · 0.70
escapeFunction · 0.70
joinMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected