Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/extensions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,12 @@ gemini extensions settings list <extension name>
and you can update a given setting using:

```
gemini extensions settings set <extension name> <setting name>
gemini extensions settings set <extension name> <setting name> [--scope <scope>]
```

- `--scope`: The scope to set the setting in (`user` or `workspace`). This is
optional and will default to `user`.

### Custom commands

Extensions can provide [custom commands](../cli/custom-commands.md) by placing
Expand Down
39 changes: 33 additions & 6 deletions packages/cli/src/commands/extensions/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,10 +18,11 @@ import { debugLogger } from '@google/gemini-cli-core';
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
Expand All @@ -33,9 +35,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;
Expand All @@ -54,6 +62,7 @@ const setCommand: CommandModule<object, SetArgs> = {
extension.id,
setting,
promptForSetting,
scope as ExtensionSettingScope,
);
},
};
Expand Down Expand Up @@ -90,12 +99,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) {
Expand All @@ -106,7 +133,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}`);
}
},
};
Expand Down
Loading