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

Function getHelpInternal

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

Source from the content-addressed store, hash-verified

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