mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 18:44:30 -07:00
82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import { type CommandModule } from 'yargs';
|
|
import { loadSettings, SettingScope } from '../../config/settings.js';
|
|
import { getErrorMessage } from '../../utils/errors.js';
|
|
import { debugLogger } from '@google/gemini-cli-core';
|
|
import { ExtensionManager } from '../../config/extension-manager.js';
|
|
import { requestConsentNonInteractive } from '../../config/extensions/consent.js';
|
|
import { promptForSetting } from '../../config/extensions/extensionSettings.js';
|
|
|
|
interface DisableArgs {
|
|
name: string;
|
|
scope?: string;
|
|
}
|
|
|
|
export function handleDisable(args: DisableArgs) {
|
|
const workspaceDir = process.cwd();
|
|
const extensionManager = new ExtensionManager({
|
|
workspaceDir,
|
|
requestConsent: requestConsentNonInteractive,
|
|
requestSetting: promptForSetting,
|
|
loadedSettings: loadSettings(workspaceDir),
|
|
});
|
|
|
|
try {
|
|
if (args.scope?.toLowerCase() === 'workspace') {
|
|
extensionManager.disableExtension(args.name, SettingScope.Workspace);
|
|
} else {
|
|
extensionManager.disableExtension(args.name, SettingScope.User);
|
|
}
|
|
debugLogger.log(
|
|
`Extension "${args.name}" successfully disabled for scope "${args.scope}".`,
|
|
);
|
|
} catch (error) {
|
|
debugLogger.error(getErrorMessage(error));
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
export const disableCommand: CommandModule = {
|
|
command: 'disable [--scope] <name>',
|
|
describe: 'Disables an extension.',
|
|
builder: (yargs) =>
|
|
yargs
|
|
.positional('name', {
|
|
describe: 'The name of the extension to disable.',
|
|
type: 'string',
|
|
})
|
|
.option('scope', {
|
|
describe: 'The scope to disable the extension in.',
|
|
type: 'string',
|
|
default: SettingScope.User,
|
|
})
|
|
.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;
|
|
}),
|
|
handler: (argv) => {
|
|
handleDisable({
|
|
name: argv['name'] as string,
|
|
scope: argv['scope'] as string,
|
|
});
|
|
},
|
|
};
|