File size: 1,190 Bytes
84aa3bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * @license
 * Copyright 2026 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import type {
  Command,
  CommandContext,
  CommandExecutionResponse,
} from './types.js';
import type { CommandRegistry } from './commandRegistry.js';

export class HelpCommand implements Command {
  readonly name = 'help';
  readonly description = 'Show available commands';

  constructor(private registry: CommandRegistry) {}

  async execute(
    _context: CommandContext,
    _args: string[] = [],
  ): Promise<CommandExecutionResponse> {
    const commands = this.registry
      .getAllCommands()
      .sort((a, b) => a.name.localeCompare(b.name));

    const lines: string[] = [];

    lines.push('Gemini CLI Help:');
    lines.push('');
    lines.push('### Basics');
    lines.push(
      '- **Add context**: Use `@` to specify files for context (e.g., `@src/myFile.ts`) to target specific files or folders.',
    );
    lines.push('');

    lines.push('### Commands');
    for (const cmd of commands) {
      if (cmd.description) {
        lines.push(`- **/${cmd.name}** - ${cmd.description}`);
      }
    }

    return {
      name: this.name,
      data: lines.join('\n'),
    };
  }
}