2025-08-26 15:49:00 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { type CommandModule } from 'yargs';
|
|
|
|
|
import { FatalConfigError, getErrorMessage } from '@google/gemini-cli-core';
|
|
|
|
|
import { enableExtension } from '../../config/extension.js';
|
|
|
|
|
import { SettingScope } from '../../config/settings.js';
|
2025-10-20 16:15:23 -07:00
|
|
|
import { ExtensionEnablementManager } from '../../config/extensions/extensionEnablement.js';
|
2025-08-26 15:49:00 +00:00
|
|
|
|
|
|
|
|
interface EnableArgs {
|
|
|
|
|
name: string;
|
2025-09-19 11:43:39 -04:00
|
|
|
scope?: string;
|
2025-08-26 15:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-16 15:51:46 -04:00
|
|
|
export function handleEnable(args: EnableArgs) {
|
2025-10-20 16:15:23 -07:00
|
|
|
const extensionEnablementManager = new ExtensionEnablementManager();
|
2025-08-26 15:49:00 +00:00
|
|
|
try {
|
2025-09-19 11:43:39 -04:00
|
|
|
if (args.scope?.toLowerCase() === 'workspace') {
|
2025-10-20 16:15:23 -07:00
|
|
|
enableExtension(
|
|
|
|
|
args.name,
|
|
|
|
|
SettingScope.Workspace,
|
|
|
|
|
extensionEnablementManager,
|
|
|
|
|
);
|
2025-09-19 11:43:39 -04:00
|
|
|
} else {
|
2025-10-20 16:15:23 -07:00
|
|
|
enableExtension(args.name, SettingScope.User, extensionEnablementManager);
|
2025-09-19 11:43:39 -04:00
|
|
|
}
|
2025-08-26 15:49:00 +00:00
|
|
|
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: CommandModule = {
|
2025-08-29 16:48:57 +00:00
|
|
|
command: 'enable [--scope] <name>',
|
2025-08-26 15:49:00 +00:00
|
|
|
describe: 'Enables an extension.',
|
|
|
|
|
builder: (yargs) =>
|
|
|
|
|
yargs
|
|
|
|
|
.positional('name', {
|
|
|
|
|
describe: 'The name of the extension to enable.',
|
|
|
|
|
type: 'string',
|
|
|
|
|
})
|
|
|
|
|
.option('scope', {
|
|
|
|
|
describe:
|
2025-10-20 16:15:23 -07:00
|
|
|
'The scope to enable the extension in. If not set, will be enabled in all scopes.',
|
2025-08-26 15:49:00 +00:00
|
|
|
type: 'string',
|
|
|
|
|
})
|
2025-09-19 11:43:39 -04:00
|
|
|
.check((argv) => {
|
|
|
|
|
if (
|
|
|
|
|
argv.scope &&
|
|
|
|
|
!Object.values(SettingScope)
|
|
|
|
|
.map((s) => s.toLowerCase())
|
|
|
|
|
.includes((argv.scope as string).toLowerCase())
|
|
|
|
|
) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`Invalid scope: ${argv.scope}. Please use one of ${Object.values(
|
|
|
|
|
SettingScope,
|
|
|
|
|
)
|
|
|
|
|
.map((s) => s.toLowerCase())
|
|
|
|
|
.join(', ')}.`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}),
|
2025-09-16 15:51:46 -04:00
|
|
|
handler: (argv) => {
|
|
|
|
|
handleEnable({
|
2025-08-26 15:49:00 +00:00
|
|
|
name: argv['name'] as string,
|
2025-09-19 11:43:39 -04:00
|
|
|
scope: argv['scope'] as string,
|
2025-08-26 15:49:00 +00:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|