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

Function getHelpInternal

packages/cli/src/internal/commandDescriptor.ts:327–432  ·  view source on GitHub ↗
(self: Instruction, config: CliConfig.CliConfig)

Source from the content-addressed store, hash-verified

325// =============================================================================
326
327const getHelpInternal = (self: Instruction, config: CliConfig.CliConfig): HelpDoc.HelpDoc => {
328 switch (self._tag) {
329 case "Standard": {
330 const header = InternalHelpDoc.isEmpty(self.description)
331 ? InternalHelpDoc.empty
332 : InternalHelpDoc.sequence(InternalHelpDoc.h1("DESCRIPTION"), self.description)
333 const argsHelp = InternalArgs.getHelp(self.args)
334 const argsSection = InternalHelpDoc.isEmpty(argsHelp)
335 ? InternalHelpDoc.empty
336 : InternalHelpDoc.sequence(InternalHelpDoc.h1("ARGUMENTS"), argsHelp)
337 const options = config.showBuiltIns
338 ? Options.all([self.options, InternalBuiltInOptions.builtIns])
339 : self.options
340 const optionsHelp = InternalOptions.getHelp(options)
341 const optionsSection = InternalHelpDoc.isEmpty(optionsHelp)
342 ? InternalHelpDoc.empty
343 : InternalHelpDoc.sequence(InternalHelpDoc.h1("OPTIONS"), optionsHelp)
344 return InternalHelpDoc.sequence(header, InternalHelpDoc.sequence(argsSection, optionsSection))
345 }
346 case "GetUserInput": {
347 return InternalHelpDoc.isEmpty(self.description)
348 ? InternalHelpDoc.empty
349 : InternalHelpDoc.sequence(InternalHelpDoc.h1("DESCRIPTION"), self.description)
350 }
351 case "Map": {
352 return getHelpInternal(self.command, config)
353 }
354 case "Subcommands": {
355 const getUsage = (
356 command: Instruction,
357 preceding: ReadonlyArray<Span.Span>
358 ): ReadonlyArray<[Span.Span, Span.Span]> => {
359 switch (command._tag) {
360 case "Standard":
361 case "GetUserInput": {
362 const usage = InternalHelpDoc.getSpan(InternalUsage.getHelp(getUsageInternal(command)))
363 const usages = Arr.append(preceding, usage)
364 const finalUsage = Arr.reduce(
365 usages,
366 InternalSpan.empty,
367 (acc, next) =>
368 InternalSpan.isText(acc) && acc.value === ""
369 ? next
370 : InternalSpan.isText(next) && next.value === ""
371 ? acc
372 : InternalSpan.spans([acc, InternalSpan.space, next])
373 )
374 const description = InternalHelpDoc.getSpan(command.description)
375 return Arr.of([finalUsage, description])
376 }
377 case "Map": {
378 return getUsage(command.command, preceding)
379 }
380 case "Subcommands": {
381 const parentUsage = getUsage(command.parent, preceding)
382 return Option.match(Arr.head(parentUsage), {
383 onNone: () =>
384 Arr.flatMap(

Callers 3

getHelpFunction · 0.70
parseBuiltInArgsFunction · 0.70
parseInternalFunction · 0.70

Calls 3

printSubcommandsFunction · 0.85
getUsageFunction · 0.70
isEmptyMethod · 0.65

Tested by

no test coverage detected