2025-10-23 08:05:43 -05:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-11-07 10:10:29 -05:00
|
|
|
import { ExtensionsCommand } from './extensions.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
|
|
|
|
|
|
|
|
class CommandRegistry {
|
|
|
|
|
private readonly commands = new Map<string, Command>();
|
|
|
|
|
|
|
|
|
|
constructor() {
|
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-10-23 08:05:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
register(command: Command) {
|
2025-11-07 10:10:29 -05:00
|
|
|
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);
|
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();
|