export class CommandRegistry {
    commands = new Map();
    aliasIndex = new Map();
    register(command) {
        this.commands.set(command.name, command);
        for (const alias of command.aliases ?? []) {
            this.aliasIndex.set(alias, command);
        }
    }
    unregister(name) {
        const command = this.commands.get(name);
        if (command) {
            for (const alias of command.aliases ?? []) {
                this.aliasIndex.delete(alias);
            }
        }
        this.commands.delete(name);
    }
    get(name) {
        return this.commands.get(name) ?? this.aliasIndex.get(name);
    }
    list() {
        return [...this.commands.values()];
    }
}
