/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { FatalConfigError, getErrorMessage } from '@vybestack/llxprt-code-core';
import { enableExtension } from '../../config/extension.js';
import { SettingScope } from '../../config/settings.js';
export async function handleEnable(args) {
    try {
        if (args.scope?.toLowerCase() === 'workspace') {
            enableExtension(args.name, SettingScope.Workspace);
        }
        else {
            enableExtension(args.name, SettingScope.User);
        }
        if (args.scope) {
            console.log(`Extension "${args.name}" successfully enabled for scope "${args.scope}".`);
        }
        else {
            console.log(`Extension "${args.name}" successfully enabled in all scopes.`);
        }
    }
    catch (error) {
        throw new FatalConfigError(getErrorMessage(error));
    }
}
export const enableCommand = {
    command: 'enable [--scope] <name>',
    describe: 'Enables an extension.',
    builder: (yargs) => yargs
        .positional('name', {
        describe: 'The name of the extension to enable.',
        type: 'string',
    })
        .option('scope', {
        describe: 'The scope to enable the extenison in. If not set, will be enabled in all scopes.',
        type: 'string',
    })
        .check((argv) => {
        if (argv.scope &&
            !Object.values(SettingScope)
                .map((s) => s.toLowerCase())
                .includes(argv.scope.toLowerCase())) {
            throw new Error(`Invalid scope: ${argv.scope}. Please use one of ${Object.values(SettingScope)
                .map((s) => s.toLowerCase())
                .join(', ')}.`);
        }
        return true;
    }),
    handler: async (argv) => {
        await handleEnable({
            name: argv['name'],
            scope: argv['scope'],
        });
    },
};
//# sourceMappingURL=enable.js.map