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

Function getZshSubcommandCases

packages/cli/src/internal/commandDescriptor.ts:1298–1396  ·  view source on GitHub ↗
(
  self: Instruction,
  parentCommands: ReadonlyArray<string>,
  subcommands: ReadonlyArray<[string, Standard | GetUserInput]>
)

Source from the content-addressed store, hash-verified

1296 }))
1297
1298const getZshSubcommandCases = (
1299 self: Instruction,
1300 parentCommands: ReadonlyArray<string>,
1301 subcommands: ReadonlyArray<[string, Standard | GetUserInput]>
1302): Array<string> => {
1303 switch (self._tag) {
1304 case "Standard":
1305 case "GetUserInput": {
1306 const options = isStandard(self)
1307 ? InternalOptions.all([InternalBuiltInOptions.builtIns, self.options])
1308 : InternalBuiltInOptions.builtIns
1309 const args = isStandard(self) ? self.args : InternalArgs.none
1310 const optionCompletions = pipe(
1311 InternalOptions.getZshCompletions(options as InternalOptions.Instruction),
1312 Arr.map((completion) => `'${completion}' \\`)
1313 )
1314 const argCompletions = pipe(
1315 InternalArgs.getZshCompletions(args as InternalArgs.Instruction),
1316 Arr.map((completion) => `'${completion}' \\`)
1317 )
1318 if (Arr.isEmptyReadonlyArray(parentCommands)) {
1319 return [
1320 "_arguments \"${_arguments_options[@]}\" \\",
1321 ...indentAll(optionCompletions, 4),
1322 ...indentAll(argCompletions, 4),
1323 ` ":: :_${self.name}_commands" \\`,
1324 ` "*::: :->${self.name}" \\`,
1325 " && ret=0"
1326 ]
1327 }
1328 if (Arr.isEmptyReadonlyArray(subcommands)) {
1329 return [
1330 `(${self.name})`,
1331 "_arguments \"${_arguments_options[@]}\" \\",
1332 ...indentAll(optionCompletions, 4),
1333 ...indentAll(argCompletions, 4),
1334 " && ret=0",
1335 ";;"
1336 ]
1337 }
1338 return [
1339 `(${self.name})`,
1340 "_arguments \"${_arguments_options[@]}\" \\",
1341 ...indentAll(optionCompletions, 4),
1342 ...indentAll(argCompletions, 4),
1343 ` ":: :_${Arr.append(parentCommands, self.name).join("__")}_commands" \\`,
1344 ` "*::: :->${self.name}" \\`,
1345 " && ret=0"
1346 ]
1347 }
1348 case "Map": {
1349 return getZshSubcommandCases(self.command, parentCommands, subcommands)
1350 }
1351 case "Subcommands": {
1352 const nextSubcommands = getSubcommandsInternal(self)
1353 const parentNames = getNamesInternal(self.parent)
1354 const parentLines = getZshSubcommandCases(
1355 self.parent,

Callers 1

Calls 7

isStandardFunction · 0.85
getSubcommandsInternalFunction · 0.85
getNamesInternalFunction · 0.85
pipeFunction · 0.70
mapMethod · 0.65
joinMethod · 0.65
ofMethod · 0.65

Tested by

no test coverage detected