2025-10-23 08:05:43 -05:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2026-01-12 16:46:42 -05:00
|
|
|
import { MemoryCommand } from './memory.js';
|
2025-12-29 15:46:10 -05:00
|
|
|
import { debugLogger } from '@google/gemini-cli-core';
|
2025-11-07 10:10:29 -05:00
|
|
|
import { ExtensionsCommand } from './extensions.js';
|
2025-12-12 12:09:04 -05:00
|
|
|
import { InitCommand } from './init.js';
|
2025-12-09 10:08:23 -05:00
|
|
|
import { RestoreCommand } from './restore.js';
|
2025-11-07 10:10:29 -05:00
|
|
|
import type { Command } from './types.js';
|
2025-10-23 08:05:43 -05:00
|
|
|
|
2026-01-06 20:09:39 -08:00
|
|
|
export class CommandRegistry {
|
2025-10-23 08:05:43 -05:00
|
|
|
private readonly commands = new Map<string, Command>();
|
|
|
|
|
|
|
|
|
|
constructor() {
|
2026-01-06 20:09:39 -08:00
|
|
|
this.initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initialize() {
|
|
|
|
|
this.commands.clear();
|
2025-11-07 10:10:29 -05:00
|
|
|
this.register(new ExtensionsCommand());
|
2025-12-09 10:08:23 -05:00
|
|
|
this.register(new RestoreCommand());
|
2025-12-12 12:09:04 -05:00
|
|
|
this.register(new InitCommand());
|
2026-01-12 16:46:42 -05:00
|
|
|
this.register(new MemoryCommand());
|
2025-10-23 08:05:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
register(command: Command) {
|
2025-11-07 10:10:29 -05:00
|
|
|
if (this.commands.has(command.name)) {
|
2025-12-29 15:46:10 -05:00
|
|
|
debugLogger.warn(`Command ${command.name} already registered. Skipping.`);
|
2025-11-07 10:10:29 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.commands.set(command.name, command);
|
|
|
|
|
|
|
|
|
|
for (const subCommand of command.subCommands ?? []) {
|
|
|
|
|
this.register(subCommand);
|
2025-10-23 08:05:43 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get(commandName: string): Command | undefined {
|
|
|
|
|
return this.commands.get(commandName);
|
|
|
|
|
}
|
2025-11-07 10:10:29 -05:00
|
|
|
|
|
|
|
|
getAllCommands(): Command[] {
|
|
|
|
|
return [...this.commands.values()];
|
|
|
|
|
}
|
2025-10-23 08:05:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const commandRegistry = new CommandRegistry();
|