Remove separate --path argument for extensions install command (#10628)

This commit is contained in:
christine betts
2025-10-07 12:01:45 -04:00
committed by GitHub
parent 343be47fa9
commit d93e987f24
4 changed files with 48 additions and 77 deletions

View File

@@ -10,12 +10,11 @@ import {
requestConsentNonInteractive,
} from '../../config/extension.js';
import type { ExtensionInstallMetadata } from '@google/gemini-cli-core';
import { getErrorMessage } from '../../utils/errors.js';
import { stat } from 'node:fs/promises';
interface InstallArgs {
source?: string;
path?: string;
source: string;
ref?: string;
autoUpdate?: boolean;
}
@@ -23,32 +22,34 @@ interface InstallArgs {
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) {
const { source } = args;
if (
source.startsWith('http://') ||
source.startsWith('https://') ||
source.startsWith('git@') ||
source.startsWith('sso://')
) {
installMetadata = {
source: args.path,
type: 'local',
source,
type: 'git',
ref: args.ref,
autoUpdate: args.autoUpdate,
};
} else {
// This should not be reached due to the yargs check.
throw new Error('Either --source or --path must be provided.');
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.');
}
}
const name = await installExtension(
@@ -63,17 +64,14 @@ export async function handleInstall(args: InstallArgs) {
}
export const installCommand: CommandModule = {
command: 'install [<source>] [--path] [--ref] [--auto-update]',
command: 'install <source>',
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.',
describe: 'The github URL or local path of the extension to install.',
type: 'string',
demandOption: true,
})
.option('ref', {
describe: 'The git ref to install from.',
@@ -83,19 +81,15 @@ export const installCommand: CommandModule = {
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.');
if (!argv.source) {
throw new Error('The source argument must be provided.');
}
return true;
}),
handler: async (argv) => {
await handleInstall({
source: argv['source'] as string | undefined,
path: argv['path'] as string | undefined,
source: argv['source'] as string,
ref: argv['ref'] as string | undefined,
autoUpdate: argv['auto-update'] as boolean | undefined,
});