mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-16 09:01:17 -07:00
Co-authored-by: Juanda <jdgarrido@google.com> Co-authored-by: Shreya Keshive <shreyakeshive@google.com>
40 lines
888 B
TypeScript
40 lines
888 B
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import { ExtensionsCommand } from './extensions.js';
|
|
import type { Command } from './types.js';
|
|
|
|
class CommandRegistry {
|
|
private readonly commands = new Map<string, Command>();
|
|
|
|
constructor() {
|
|
this.register(new ExtensionsCommand());
|
|
}
|
|
|
|
register(command: Command) {
|
|
if (this.commands.has(command.name)) {
|
|
console.warn(`Command ${command.name} already registered. Skipping.`);
|
|
return;
|
|
}
|
|
|
|
this.commands.set(command.name, command);
|
|
|
|
for (const subCommand of command.subCommands ?? []) {
|
|
this.register(subCommand);
|
|
}
|
|
}
|
|
|
|
get(commandName: string): Command | undefined {
|
|
return this.commands.get(commandName);
|
|
}
|
|
|
|
getAllCommands(): Command[] {
|
|
return [...this.commands.values()];
|
|
}
|
|
}
|
|
|
|
export const commandRegistry = new CommandRegistry();
|