| 2074 | |
| 2075 | /** @internal */ |
| 2076 | export const getBashCompletions = (self: Instruction): ReadonlyArray<string> => { |
| 2077 | switch (self._tag) { |
| 2078 | case "Empty": { |
| 2079 | return Arr.empty() |
| 2080 | } |
| 2081 | case "Single": { |
| 2082 | const names = getNames(self) |
| 2083 | const cases = Arr.join(names, "|") |
| 2084 | const compgen = InternalPrimitive.getBashCompletions( |
| 2085 | self.primitiveType as InternalPrimitive.Instruction |
| 2086 | ) |
| 2087 | return Arr.make( |
| 2088 | `${cases})`, |
| 2089 | ` COMPREPLY=( ${compgen} )`, |
| 2090 | ` return 0`, |
| 2091 | ` ;;` |
| 2092 | ) |
| 2093 | } |
| 2094 | case "KeyValueMap": |
| 2095 | case "Variadic": { |
| 2096 | return getBashCompletions(self.argumentOption as Instruction) |
| 2097 | } |
| 2098 | case "Map": |
| 2099 | case "WithDefault": |
| 2100 | case "WithFallback": { |
| 2101 | return getBashCompletions(self.options as Instruction) |
| 2102 | } |
| 2103 | case "Both": |
| 2104 | case "OrElse": { |
| 2105 | const left = getBashCompletions(self.left as Instruction) |
| 2106 | const right = getBashCompletions(self.right as Instruction) |
| 2107 | return Arr.appendAll(left, right) |
| 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | /** @internal */ |
| 2113 | export const getFishCompletions = (self: Instruction): Array<string> => { |