Add support for user-scoped extension settings (#13748)

This commit is contained in:
christine betts
2025-12-08 17:51:26 -05:00
committed by GitHub
parent 91c46311c8
commit ec9a8c7a72
4 changed files with 322 additions and 158 deletions

View File

@@ -6,9 +6,10 @@
import type { CommandModule } from 'yargs';
import {
getEnvContents,
updateSetting,
promptForSetting,
ExtensionSettingScope,
getScopedEnvContents,
} from '../../config/extensions/extensionSettings.js';
import { getExtensionAndManager } from './utils.js';
import { debugLogger } from '@google/gemini-cli-core';
@@ -18,10 +19,11 @@ import { exitCli } from '../utils.js';
interface SetArgs {
name: string;
setting: string;
scope: string;
}
const setCommand: CommandModule<object, SetArgs> = {
command: 'set <name> <setting>',
command: 'set [--scope] <name> <setting>',
describe: 'Set a specific setting for an extension.',
builder: (yargs) =>
yargs
@@ -34,9 +36,15 @@ const setCommand: CommandModule<object, SetArgs> = {
describe: 'The setting to configure (name or env var).',
type: 'string',
demandOption: true,
})
.option('scope', {
describe: 'The scope to set the setting in.',
type: 'string',
choices: ['user', 'workspace'],
default: 'user',
}),
handler: async (args) => {
const { name, setting } = args;
const { name, setting, scope } = args;
const { extension, extensionManager } = await getExtensionAndManager(name);
if (!extension || !extensionManager) {
return;
@@ -55,6 +63,7 @@ const setCommand: CommandModule<object, SetArgs> = {
extension.id,
setting,
promptForSetting,
scope as ExtensionSettingScope,
);
await exitCli();
},
@@ -92,12 +101,30 @@ const listCommand: CommandModule<object, ListArgs> = {
return;
}
const currentSettings = await getEnvContents(extensionConfig, extension.id);
const userSettings = await getScopedEnvContents(
extensionConfig,
extension.id,
ExtensionSettingScope.USER,
);
const workspaceSettings = await getScopedEnvContents(
extensionConfig,
extension.id,
ExtensionSettingScope.WORKSPACE,
);
const mergedSettings = { ...userSettings, ...workspaceSettings };
debugLogger.log(`Settings for "${name}":`);
for (const setting of extensionConfig.settings) {
const value = currentSettings[setting.envVar];
const value = mergedSettings[setting.envVar];
let displayValue: string;
let scopeInfo = '';
if (workspaceSettings[setting.envVar] !== undefined) {
scopeInfo = ' (workspace)';
} else if (userSettings[setting.envVar] !== undefined) {
scopeInfo = ' (user)';
}
if (value === undefined) {
displayValue = '[not set]';
} else if (setting.sensitive) {
@@ -108,7 +135,7 @@ const listCommand: CommandModule<object, ListArgs> = {
debugLogger.log(`
- ${setting.name} (${setting.envVar})`);
debugLogger.log(` Description: ${setting.description}`);
debugLogger.log(` Value: ${displayValue}`);
debugLogger.log(` Value: ${displayValue}${scopeInfo}`);
}
await exitCli();
},