@swell/cli
Version:
Swell's command line interface/utility
90 lines (89 loc) • 3.93 kB
TypeScript
import { Command, Help } from '@oclif/core';
/**
* Custom Help class for Swell CLI
*
* Renders help in a cleaner format with:
* - Two-line USAGE with "# interactive" comment
* - Grouped flags by category (type options vs general)
* - Custom sections for conditional dependencies (TYPE OPTIONS, APP TYPES, etc.)
*
* Commands opt-in to custom formatting by defining a static `helpMeta` property.
* Commands without helpMeta use standard oclif formatting.
*/
export default class CustomHelp extends Help {
/**
* Override showCommandHelp to prevent duplicate summary for commands with helpMeta.
* The default implementation logs summary separately, but our formatCommand includes it.
* @param command - The command to display help for
* @returns Promise that resolves when help is displayed
*/
showCommandHelp(command: Command.Loadable): Promise<void>;
/**
* Override formatCommand to provide custom help output for commands with helpMeta.
* Falls back to default formatting for commands without helpMeta.
* @param command - The command to format help for
* @returns Formatted help text as a string
*/
protected formatCommand(command: Command.Loadable): string;
/**
* Get helpMeta from a command, handling the Command.Loadable type.
* The helpMeta is stored on the command class itself, accessible via the cached command.
* @param command - The command to extract helpMeta from
* @returns The helpMeta object if present on the command, otherwise undefined
*/
private getHelpMeta;
/**
* Format USAGE section with two-line pattern:
* - Line 1: Interactive mode (no args) with "# interactive" comment
* - Line 2: Direct/non-interactive mode with args
* @param command - The command to format usage for
* @param helpMeta - The help metadata for the command
* @returns Formatted USAGE section as an array of strings
*/
private formatUsageSection;
/**
* Auto-generate direct usage line from command definition.
* @param command - The command to generate direct usage for
* @returns The generated direct usage line as a string
*/
private generateDirectUsage;
/**
* Format ARGUMENTS section with compact display.
* @param command - The command to format arguments for
* @returns Formatted ARGUMENTS section as an array of strings
*/
private formatArgumentsSection;
/**
* Format TYPE section (APP TYPES, etc.) with requires/optional indicators.
* @param section - The type section configuration with types and their requirements
* @returns Formatted TYPE section as an array of strings
*/
private formatTypeSection;
/**
* Format VARIANT section (TRIGGER OPTIONS, etc.) - compact inline format.
* @param section - The variant section configuration with variants and their descriptions
* @returns Formatted VARIANT section as an array of strings
*/
private formatVariantSection;
/**
* Format FLAGS section with filtering and sorting.
* @param command - The command to format flags for
* @param title - The section title to display
* @param filter - Function to filter flags by name
* @returns Formatted FLAGS section as an array of strings
*/
private formatFlagsSection;
/**
* Format DESCRIPTION section - shows description if it differs from summary.
* Only shown when there's meaningful additional content.
* @param command - The command to format description for
* @returns Formatted DESCRIPTION section as an array of strings
*/
private formatDescriptionSection;
/**
* Format EXAMPLES section - clean, label-free examples.
* @param command - The command to format examples for
* @returns Formatted EXAMPLES section as an array of strings
*/
private formatExamplesSection;
}