2025-08-25 17:02:10 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-26 00:04:53 +02:00
|
|
|
import type { CommandModule } from 'yargs';
|
2025-09-25 10:57:59 -07:00
|
|
|
import {
|
|
|
|
|
installExtension,
|
|
|
|
|
requestConsentNonInteractive,
|
|
|
|
|
} from '../../config/extension.js';
|
2025-09-17 18:14:01 -04:00
|
|
|
import type { ExtensionInstallMetadata } from '@google/gemini-cli-core';
|
2025-08-26 14:36:55 +00:00
|
|
|
import { getErrorMessage } from '../../utils/errors.js';
|
2025-10-07 12:01:45 -04:00
|
|
|
import { stat } from 'node:fs/promises';
|
2025-08-26 14:36:55 +00:00
|
|
|
|
2025-08-25 17:02:10 +00:00
|
|
|
interface InstallArgs {
|
2025-10-07 12:01:45 -04:00
|
|
|
source: string;
|
2025-09-10 09:35:48 -07:00
|
|
|
ref?: string;
|
2025-09-18 14:49:47 -07:00
|
|
|
autoUpdate?: boolean;
|
2025-08-25 17:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function handleInstall(args: InstallArgs) {
|
|
|
|
|
try {
|
2025-09-02 08:15:47 -07:00
|
|
|
let installMetadata: ExtensionInstallMetadata;
|
2025-10-07 12:01:45 -04:00
|
|
|
const { source } = args;
|
|
|
|
|
if (
|
|
|
|
|
source.startsWith('http://') ||
|
|
|
|
|
source.startsWith('https://') ||
|
|
|
|
|
source.startsWith('git@') ||
|
|
|
|
|
source.startsWith('sso://')
|
|
|
|
|
) {
|
2025-09-02 08:15:47 -07:00
|
|
|
installMetadata = {
|
2025-10-07 12:01:45 -04:00
|
|
|
source,
|
|
|
|
|
type: 'git',
|
|
|
|
|
ref: args.ref,
|
2025-09-18 14:49:47 -07:00
|
|
|
autoUpdate: args.autoUpdate,
|
2025-09-02 08:15:47 -07:00
|
|
|
};
|
|
|
|
|
} else {
|
2025-10-07 12:01:45 -04:00
|
|
|
if (args.ref || args.autoUpdate) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'--ref and --auto-update are not applicable for local extensions.',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await stat(source);
|
|
|
|
|
installMetadata = {
|
|
|
|
|
source,
|
|
|
|
|
type: 'local',
|
|
|
|
|
};
|
|
|
|
|
} catch {
|
|
|
|
|
throw new Error('Install source not found.');
|
|
|
|
|
}
|
2025-09-02 08:15:47 -07:00
|
|
|
}
|
|
|
|
|
|
2025-09-25 10:57:59 -07:00
|
|
|
const name = await installExtension(
|
|
|
|
|
installMetadata,
|
|
|
|
|
requestConsentNonInteractive,
|
|
|
|
|
);
|
2025-09-09 12:12:56 -04:00
|
|
|
console.log(`Extension "${name}" installed successfully and enabled.`);
|
2025-08-25 17:02:10 +00:00
|
|
|
} catch (error) {
|
2025-08-26 14:36:55 +00:00
|
|
|
console.error(getErrorMessage(error));
|
2025-08-25 17:02:10 +00:00
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const installCommand: CommandModule = {
|
2025-10-07 12:01:45 -04:00
|
|
|
command: 'install <source>',
|
2025-09-08 21:59:45 -07:00
|
|
|
describe: 'Installs an extension from a git repository URL or a local path.',
|
2025-08-25 17:02:10 +00:00
|
|
|
builder: (yargs) =>
|
|
|
|
|
yargs
|
2025-09-05 11:44:41 -07:00
|
|
|
.positional('source', {
|
2025-10-07 12:01:45 -04:00
|
|
|
describe: 'The github URL or local path of the extension to install.',
|
2025-08-25 17:02:10 +00:00
|
|
|
type: 'string',
|
2025-10-07 12:01:45 -04:00
|
|
|
demandOption: true,
|
2025-08-25 17:02:10 +00:00
|
|
|
})
|
2025-09-10 09:35:48 -07:00
|
|
|
.option('ref', {
|
|
|
|
|
describe: 'The git ref to install from.',
|
|
|
|
|
type: 'string',
|
|
|
|
|
})
|
2025-09-18 14:49:47 -07:00
|
|
|
.option('auto-update', {
|
|
|
|
|
describe: 'Enable auto-update for this extension.',
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
})
|
2025-08-25 17:02:10 +00:00
|
|
|
.check((argv) => {
|
2025-10-07 12:01:45 -04:00
|
|
|
if (!argv.source) {
|
|
|
|
|
throw new Error('The source argument must be provided.');
|
2025-08-25 17:02:10 +00:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}),
|
|
|
|
|
handler: async (argv) => {
|
|
|
|
|
await handleInstall({
|
2025-10-07 12:01:45 -04:00
|
|
|
source: argv['source'] as string,
|
2025-09-10 09:35:48 -07:00
|
|
|
ref: argv['ref'] as string | undefined,
|
2025-09-18 14:49:47 -07:00
|
|
|
autoUpdate: argv['auto-update'] as boolean | undefined,
|
2025-08-25 17:02:10 +00:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|