mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-15 20:40:35 -07:00
Support installing extensions with org/repo (#7364)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
This commit is contained in:
@@ -17,12 +17,43 @@ interface InstallArgs {
|
||||
path?: string;
|
||||
}
|
||||
|
||||
const ORG_REPO_REGEX = /^[a-zA-Z0-9-]+\/[\w.-]+$/;
|
||||
|
||||
export async function handleInstall(args: InstallArgs) {
|
||||
try {
|
||||
const installMetadata: ExtensionInstallMetadata = {
|
||||
source: (args.source || args.path) as string,
|
||||
type: args.source ? 'git' : 'local',
|
||||
};
|
||||
let installMetadata: ExtensionInstallMetadata;
|
||||
|
||||
if (args.source) {
|
||||
const { source } = args;
|
||||
if (
|
||||
source.startsWith('http://') ||
|
||||
source.startsWith('https://') ||
|
||||
source.startsWith('git@')
|
||||
) {
|
||||
installMetadata = {
|
||||
source,
|
||||
type: 'git',
|
||||
};
|
||||
} else if (ORG_REPO_REGEX.test(source)) {
|
||||
installMetadata = {
|
||||
source: `https://github.com/${source}.git`,
|
||||
type: 'git',
|
||||
};
|
||||
} else {
|
||||
throw new Error(
|
||||
`The source "${source}" is not a valid URL or "org/repo" format.`,
|
||||
);
|
||||
}
|
||||
} else if (args.path) {
|
||||
installMetadata = {
|
||||
source: args.path,
|
||||
type: 'local',
|
||||
};
|
||||
} else {
|
||||
// This should not be reached due to the yargs check.
|
||||
throw new Error('Either --source or --path must be provided.');
|
||||
}
|
||||
|
||||
const extensionName = await installExtension(installMetadata);
|
||||
console.log(
|
||||
`Extension "${extensionName}" installed successfully and enabled.`,
|
||||
@@ -35,11 +66,12 @@ export async function handleInstall(args: InstallArgs) {
|
||||
|
||||
export const installCommand: CommandModule = {
|
||||
command: 'install [--source | --path ]',
|
||||
describe: 'Installs an extension from a git repository or a local path.',
|
||||
describe:
|
||||
'Installs an extension from a git repository (URL or "org/repo") or a local path.',
|
||||
builder: (yargs) =>
|
||||
yargs
|
||||
.option('source', {
|
||||
describe: 'The git URL of the extension to install.',
|
||||
describe: 'The git URL or "org/repo" of the extension to install.',
|
||||
type: 'string',
|
||||
})
|
||||
.option('path', {
|
||||
@@ -49,9 +81,7 @@ export const installCommand: CommandModule = {
|
||||
.conflicts('source', 'path')
|
||||
.check((argv) => {
|
||||
if (!argv.source && !argv.path) {
|
||||
throw new Error(
|
||||
'Either a git URL --source or a --path must be provided.',
|
||||
);
|
||||
throw new Error('Either --source or --path must be provided.');
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user