mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 02:24:09 -07:00
4a92f938e1
Co-authored-by: hritan <48129645+hritan@users.noreply.github.com> Co-authored-by: Taneja Hriday <hridayt@google.com> Co-authored-by: shishu314 <shishu_1998@yahoo.com> Co-authored-by: Shi Shu <shii@google.com> Co-authored-by: Jacob MacDonald <jakemac@google.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
98 lines
2.8 KiB
TypeScript
98 lines
2.8 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import type { CommandModule } from 'yargs';
|
|
import { installExtension } from '../../config/extension.js';
|
|
import type { ExtensionInstallMetadata } from '@google/gemini-cli-core';
|
|
|
|
import { getErrorMessage } from '../../utils/errors.js';
|
|
|
|
interface InstallArgs {
|
|
source?: string;
|
|
path?: string;
|
|
ref?: string;
|
|
autoUpdate?: boolean;
|
|
}
|
|
|
|
export async function handleInstall(args: InstallArgs) {
|
|
try {
|
|
let installMetadata: ExtensionInstallMetadata;
|
|
if (args.source) {
|
|
const { source } = args;
|
|
if (
|
|
source.startsWith('http://') ||
|
|
source.startsWith('https://') ||
|
|
source.startsWith('git@') ||
|
|
source.startsWith('sso://')
|
|
) {
|
|
installMetadata = {
|
|
source,
|
|
type: 'git',
|
|
ref: args.ref,
|
|
autoUpdate: args.autoUpdate,
|
|
};
|
|
} else {
|
|
throw new Error(`The source "${source}" is not a valid URL format.`);
|
|
}
|
|
} else if (args.path) {
|
|
installMetadata = {
|
|
source: args.path,
|
|
type: 'local',
|
|
autoUpdate: args.autoUpdate,
|
|
};
|
|
} else {
|
|
// This should not be reached due to the yargs check.
|
|
throw new Error('Either --source or --path must be provided.');
|
|
}
|
|
|
|
const name = await installExtension(installMetadata, true);
|
|
console.log(`Extension "${name}" installed successfully and enabled.`);
|
|
} catch (error) {
|
|
console.error(getErrorMessage(error));
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
export const installCommand: CommandModule = {
|
|
command: 'install [<source>] [--path] [--ref] [--auto-update]',
|
|
describe: 'Installs an extension from a git repository URL or a local path.',
|
|
builder: (yargs) =>
|
|
yargs
|
|
.positional('source', {
|
|
describe: 'The github URL of the extension to install.',
|
|
type: 'string',
|
|
})
|
|
.option('path', {
|
|
describe: 'Path to a local extension directory.',
|
|
type: 'string',
|
|
})
|
|
.option('ref', {
|
|
describe: 'The git ref to install from.',
|
|
type: 'string',
|
|
})
|
|
.option('auto-update', {
|
|
describe: 'Enable auto-update for this extension.',
|
|
type: 'boolean',
|
|
})
|
|
.conflicts('source', 'path')
|
|
.conflicts('path', 'ref')
|
|
.conflicts('path', 'auto-update')
|
|
.check((argv) => {
|
|
if (!argv.source && !argv.path) {
|
|
throw new Error('Either source or --path must be provided.');
|
|
}
|
|
return true;
|
|
}),
|
|
handler: async (argv) => {
|
|
await handleInstall({
|
|
source: argv['source'] as string | undefined,
|
|
path: argv['path'] as string | undefined,
|
|
ref: argv['ref'] as string | undefined,
|
|
autoUpdate: argv['auto-update'] as boolean | undefined,
|
|
});
|
|
},
|
|
};
|