-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathlist.ts
More file actions
70 lines (66 loc) · 2.1 KB
/
list.ts
File metadata and controls
70 lines (66 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type { CommandModule } from 'yargs';
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 { loadSettings } from '../../config/settings.js';
import { promptForSetting } from '../../config/extensions/extensionSettings.js';
import { exitCli } from '../utils.js';
export async function handleList(options?: { outputFormat?: 'text' | 'json' }) {
try {
const workspaceDir = process.cwd();
const extensionManager = new ExtensionManager({
workspaceDir,
requestConsent: requestConsentNonInteractive,
requestSetting: promptForSetting,
settings: loadSettings(workspaceDir).merged,
});
const extensions = await extensionManager.loadExtensions();
if (extensions.length === 0) {
if (options?.outputFormat === 'json') {
debugLogger.log('[]');
} else {
debugLogger.log('No extensions installed.');
}
return;
}
if (options?.outputFormat === 'json') {
debugLogger.log(JSON.stringify(extensions, null, 2));
} else {
debugLogger.log(
extensions
.map((extension, _): string =>
extensionManager.toOutputString(extension),
)
.join('\n\n'),
);
}
} catch (error) {
debugLogger.error(getErrorMessage(error));
process.exit(1);
}
}
export const listCommand: CommandModule = {
command: 'list',
describe: 'Lists installed extensions.',
builder: (yargs) =>
yargs.option('output-format', {
alias: 'o',
type: 'string',
describe: 'The format of the CLI output.',
choices: ['text', 'json'],
default: 'text',
}),
handler: async (argv) => {
await handleList({
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
outputFormat: argv['output-format'] as 'text' | 'json',
});
await exitCli();
},
};