generateCommandHelp static method

String generateCommandHelp(
  1. CommandDefinition command, {
  2. ToolDefinition? tool,
})

Generate command-level help text.

Shows command description, usage, and all options including inherited traversal options.

Implementation

static String generateCommandHelp(
  CommandDefinition command, {
  ToolDefinition? tool,
}) {
  final buf = StringBuffer();
  final toolName = tool?.name ?? 'tool';

  // Header
  buf.writeln('**:${command.name}**');
  if (command.aliases.isNotEmpty) {
    buf.writeln('Aliases: ${command.aliases.map((a) => ':$a').join(', ')}');
  }
  buf.writeln();
  buf.writeln(command.description);
  buf.writeln();

  // Usage
  buf.writeln('<cyan>**Usage**</cyan>');
  buf.writeln('  $toolName [global-options] :${command.name} [options]');
  buf.writeln();

  // Command options
  if (command.options.isNotEmpty) {
    buf.writeln('<yellow>**Command Options**</yellow>');
    _writeOptions(buf, command.options);
    buf.writeln();
  }

  // Traversal options
  if (command.supportsProjectTraversal) {
    buf.writeln('<yellow>**Project Traversal Options**</yellow>');
    _writeOptions(buf, projectTraversalOptions);
    buf.writeln();
  }

  if (command.supportsGitTraversal) {
    buf.writeln('<yellow>**Git Traversal Options**</yellow>');
    _writeOptions(buf, gitTraversalOptions);
    buf.writeln();
  }

  // Per-command filters
  if (command.supportsPerCommandFilter) {
    buf.writeln('<dim>This command supports per-command --project and --exclude filters.</dim>');
    buf.writeln();
  }

  // Nature requirements
  if (command.requiredNatures != null && command.requiredNatures!.isNotEmpty) {
    buf.writeln('<dim>Requires: ${command.requiredNatures!.map(_natureName).join(', ')}</dim>');
    buf.writeln();
  }

  // Examples
  if (command.examples.isNotEmpty) {
    buf.writeln('<green>**Examples**</green>');
    for (final example in command.examples) {
      buf.writeln('  $example');
    }
    buf.writeln();
  }

  return buf.toString();
}