({
command,
rootName,
ancestors,
depth,
useRootIntro,
}: BuildCommandSectionOptions)
| 380 | }; |
| 381 | |
| 382 | function buildCommandSection({ |
| 383 | command, |
| 384 | rootName, |
| 385 | ancestors, |
| 386 | depth, |
| 387 | useRootIntro, |
| 388 | }: BuildCommandSectionOptions): Content[] { |
| 389 | const nodes: Content[] = []; |
| 390 | const commandPath = getCommandPath(rootName, ancestors, command); |
| 391 | const isRootCommand = ancestors.length === 0; |
| 392 | const shouldUseIntro = isRootCommand && useRootIntro; |
| 393 | const headingContent = shouldUseIntro |
| 394 | ? "Introduction" |
| 395 | : [createInlineCode(commandPath)]; |
| 396 | |
| 397 | nodes.push(createHeading(depth, headingContent)); |
| 398 | |
| 399 | const description = command.description(); |
| 400 | if (description) { |
| 401 | nodes.push(createParagraph(description)); |
| 402 | } |
| 403 | |
| 404 | const usage = buildUsage(command); |
| 405 | if (usage) { |
| 406 | const sectionDepth = shouldUseIntro ? depth : Math.min(depth + 1, 6); |
| 407 | nodes.push(createHeading(sectionDepth, "Usage")); |
| 408 | nodes.push({ |
| 409 | type: "paragraph", |
| 410 | children: [createInlineCode(usage)], |
| 411 | }); |
| 412 | } |
| 413 | |
| 414 | const aliases = command.aliases(); |
| 415 | if (aliases.length > 0) { |
| 416 | const sectionDepth = shouldUseIntro ? depth : Math.min(depth + 1, 6); |
| 417 | nodes.push(createHeading(sectionDepth, "Aliases")); |
| 418 | nodes.push( |
| 419 | createList( |
| 420 | aliases.map((alias) => createListItem([createInlineCode(alias)])), |
| 421 | ), |
| 422 | ); |
| 423 | } |
| 424 | |
| 425 | const args = command.registeredArguments ?? []; |
| 426 | if (args.length > 0) { |
| 427 | const sectionDepth = shouldUseIntro ? depth : Math.min(depth + 1, 6); |
| 428 | nodes.push(createHeading(sectionDepth, "Arguments")); |
| 429 | nodes.push(createList(buildArgumentListItems(args))); |
| 430 | } |
| 431 | |
| 432 | const visibleOptions = command.options.filter((option) => !option.hidden); |
| 433 | if (visibleOptions.length > 0) { |
| 434 | const { flags, valueOptions } = partitionOptions(visibleOptions); |
| 435 | const sectionDepth = shouldUseIntro ? depth : Math.min(depth + 1, 6); |
| 436 | |
| 437 | if (valueOptions.length > 0) { |
| 438 | nodes.push(createHeading(sectionDepth, "Options")); |
| 439 | nodes.push( |
no test coverage detected