mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-04 18:31:36 -07:00
Add support for user-scoped extension settings (#13748)
This commit is contained in:
@@ -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();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user