mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-27 21:44:25 -07:00
Remove separate --path argument for extensions install command (#10628)
This commit is contained in:
@@ -18,7 +18,7 @@ Note that all of these commands will only be reflected in active CLI sessions on
|
|||||||
|
|
||||||
### Installing an extension
|
### Installing an extension
|
||||||
|
|
||||||
You can install an extension using `gemini extensions install` with either a GitHub URL source or `--path=some/local/path`.
|
You can install an extension using `gemini extensions install` with either a GitHub URL or a local path`.
|
||||||
|
|
||||||
Note that we create a copy of the installed extension, so you will need to run `gemini extensions update` to pull in changes from both locally-defined extensions and those on GitHub.
|
Note that we create a copy of the installed extension, so you will need to run `gemini extensions update` to pull in changes from both locally-defined extensions and those on GitHub.
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ test('installs a local extension, verifies a command, and updates it', async ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await rig.runCommand(
|
const result = await rig.runCommand(
|
||||||
['extensions', 'install', `--path=${rig.testDir!}`],
|
['extensions', 'install', `${rig.testDir!}`],
|
||||||
{ stdin: 'y\n' },
|
{ stdin: 'y\n' },
|
||||||
);
|
);
|
||||||
expect(result).toContain('test-extension');
|
expect(result).toContain('test-extension');
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import yargs from 'yargs';
|
|||||||
|
|
||||||
const mockInstallExtension = vi.hoisted(() => vi.fn());
|
const mockInstallExtension = vi.hoisted(() => vi.fn());
|
||||||
const mockRequestConsentNonInteractive = vi.hoisted(() => vi.fn());
|
const mockRequestConsentNonInteractive = vi.hoisted(() => vi.fn());
|
||||||
|
const mockStat = vi.hoisted(() => vi.fn());
|
||||||
|
|
||||||
vi.mock('../../config/extension.js', () => ({
|
vi.mock('../../config/extension.js', () => ({
|
||||||
installExtension: mockInstallExtension,
|
installExtension: mockInstallExtension,
|
||||||
@@ -20,35 +21,20 @@ vi.mock('../../utils/errors.js', () => ({
|
|||||||
getErrorMessage: vi.fn((error: Error) => error.message),
|
getErrorMessage: vi.fn((error: Error) => error.message),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock('node:fs/promises', () => ({
|
||||||
|
stat: mockStat,
|
||||||
|
default: {
|
||||||
|
stat: mockStat,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
describe('extensions install command', () => {
|
describe('extensions install command', () => {
|
||||||
it('should fail if no source is provided', () => {
|
it('should fail if no source is provided', () => {
|
||||||
const validationParser = yargs([]).command(installCommand).fail(false);
|
const validationParser = yargs([]).command(installCommand).fail(false);
|
||||||
expect(() => validationParser.parse('install')).toThrow(
|
expect(() => validationParser.parse('install')).toThrow(
|
||||||
'Either source or --path must be provided.',
|
'Not enough non-option arguments: got 0, need at least 1',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if both git source and local path are provided', () => {
|
|
||||||
const validationParser = yargs([])
|
|
||||||
.command(installCommand)
|
|
||||||
.fail(false)
|
|
||||||
.locale('en');
|
|
||||||
expect(() =>
|
|
||||||
validationParser.parse('install some-url --path /some/path'),
|
|
||||||
).toThrow('Arguments source and path are mutually exclusive');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail if both auto update and local path are provided', () => {
|
|
||||||
const validationParser = yargs([])
|
|
||||||
.command(installCommand)
|
|
||||||
.fail(false)
|
|
||||||
.locale('en');
|
|
||||||
expect(() =>
|
|
||||||
validationParser.parse(
|
|
||||||
'install some-url --path /some/path --auto-update',
|
|
||||||
),
|
|
||||||
).toThrow('Arguments path and auto-update are mutually exclusive');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('handleInstall', () => {
|
describe('handleInstall', () => {
|
||||||
@@ -67,6 +53,7 @@ describe('handleInstall', () => {
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mockInstallExtension.mockClear();
|
mockInstallExtension.mockClear();
|
||||||
mockRequestConsentNonInteractive.mockClear();
|
mockRequestConsentNonInteractive.mockClear();
|
||||||
|
mockStat.mockClear();
|
||||||
vi.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -107,13 +94,12 @@ describe('handleInstall', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('throws an error from an unknown source', async () => {
|
it('throws an error from an unknown source', async () => {
|
||||||
|
mockStat.mockRejectedValue(new Error('ENOENT: no such file or directory'));
|
||||||
await handleInstall({
|
await handleInstall({
|
||||||
source: 'test://google.com',
|
source: 'test://google.com',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
expect(consoleErrorSpy).toHaveBeenCalledWith('Install source not found.');
|
||||||
'The source "test://google.com" is not a valid URL format.',
|
|
||||||
);
|
|
||||||
expect(processSpy).toHaveBeenCalledWith(1);
|
expect(processSpy).toHaveBeenCalledWith(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -131,9 +117,9 @@ describe('handleInstall', () => {
|
|||||||
|
|
||||||
it('should install an extension from a local path', async () => {
|
it('should install an extension from a local path', async () => {
|
||||||
mockInstallExtension.mockResolvedValue('local-extension');
|
mockInstallExtension.mockResolvedValue('local-extension');
|
||||||
|
mockStat.mockResolvedValue({});
|
||||||
await handleInstall({
|
await handleInstall({
|
||||||
path: '/some/path',
|
source: '/some/path',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(consoleLogSpy).toHaveBeenCalledWith(
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
||||||
@@ -141,15 +127,6 @@ describe('handleInstall', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if no source or path is provided', async () => {
|
|
||||||
await handleInstall({});
|
|
||||||
|
|
||||||
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
||||||
'Either --source or --path must be provided.',
|
|
||||||
);
|
|
||||||
expect(processSpy).toHaveBeenCalledWith(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if install extension fails', async () => {
|
it('should throw an error if install extension fails', async () => {
|
||||||
mockInstallExtension.mockRejectedValue(
|
mockInstallExtension.mockRejectedValue(
|
||||||
new Error('Install extension failed'),
|
new Error('Install extension failed'),
|
||||||
|
|||||||
@@ -10,12 +10,11 @@ import {
|
|||||||
requestConsentNonInteractive,
|
requestConsentNonInteractive,
|
||||||
} from '../../config/extension.js';
|
} from '../../config/extension.js';
|
||||||
import type { ExtensionInstallMetadata } from '@google/gemini-cli-core';
|
import type { ExtensionInstallMetadata } from '@google/gemini-cli-core';
|
||||||
|
|
||||||
import { getErrorMessage } from '../../utils/errors.js';
|
import { getErrorMessage } from '../../utils/errors.js';
|
||||||
|
import { stat } from 'node:fs/promises';
|
||||||
|
|
||||||
interface InstallArgs {
|
interface InstallArgs {
|
||||||
source?: string;
|
source: string;
|
||||||
path?: string;
|
|
||||||
ref?: string;
|
ref?: string;
|
||||||
autoUpdate?: boolean;
|
autoUpdate?: boolean;
|
||||||
}
|
}
|
||||||
@@ -23,32 +22,34 @@ interface InstallArgs {
|
|||||||
export async function handleInstall(args: InstallArgs) {
|
export async function handleInstall(args: InstallArgs) {
|
||||||
try {
|
try {
|
||||||
let installMetadata: ExtensionInstallMetadata;
|
let installMetadata: ExtensionInstallMetadata;
|
||||||
if (args.source) {
|
const { source } = args;
|
||||||
const { source } = args;
|
if (
|
||||||
if (
|
source.startsWith('http://') ||
|
||||||
source.startsWith('http://') ||
|
source.startsWith('https://') ||
|
||||||
source.startsWith('https://') ||
|
source.startsWith('git@') ||
|
||||||
source.startsWith('git@') ||
|
source.startsWith('sso://')
|
||||||
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 = {
|
installMetadata = {
|
||||||
source: args.path,
|
source,
|
||||||
type: 'local',
|
type: 'git',
|
||||||
|
ref: args.ref,
|
||||||
autoUpdate: args.autoUpdate,
|
autoUpdate: args.autoUpdate,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// This should not be reached due to the yargs check.
|
if (args.ref || args.autoUpdate) {
|
||||||
throw new Error('Either --source or --path must be provided.');
|
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(
|
const name = await installExtension(
|
||||||
@@ -63,17 +64,14 @@ export async function handleInstall(args: InstallArgs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const installCommand: CommandModule = {
|
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.',
|
describe: 'Installs an extension from a git repository URL or a local path.',
|
||||||
builder: (yargs) =>
|
builder: (yargs) =>
|
||||||
yargs
|
yargs
|
||||||
.positional('source', {
|
.positional('source', {
|
||||||
describe: 'The github URL of the extension to install.',
|
describe: 'The github URL or local path of the extension to install.',
|
||||||
type: 'string',
|
|
||||||
})
|
|
||||||
.option('path', {
|
|
||||||
describe: 'Path to a local extension directory.',
|
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
demandOption: true,
|
||||||
})
|
})
|
||||||
.option('ref', {
|
.option('ref', {
|
||||||
describe: 'The git ref to install from.',
|
describe: 'The git ref to install from.',
|
||||||
@@ -83,19 +81,15 @@ export const installCommand: CommandModule = {
|
|||||||
describe: 'Enable auto-update for this extension.',
|
describe: 'Enable auto-update for this extension.',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
})
|
})
|
||||||
.conflicts('source', 'path')
|
|
||||||
.conflicts('path', 'ref')
|
|
||||||
.conflicts('path', 'auto-update')
|
|
||||||
.check((argv) => {
|
.check((argv) => {
|
||||||
if (!argv.source && !argv.path) {
|
if (!argv.source) {
|
||||||
throw new Error('Either source or --path must be provided.');
|
throw new Error('The source argument must be provided.');
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
handler: async (argv) => {
|
handler: async (argv) => {
|
||||||
await handleInstall({
|
await handleInstall({
|
||||||
source: argv['source'] as string | undefined,
|
source: argv['source'] as string,
|
||||||
path: argv['path'] as string | undefined,
|
|
||||||
ref: argv['ref'] as string | undefined,
|
ref: argv['ref'] as string | undefined,
|
||||||
autoUpdate: argv['auto-update'] as boolean | undefined,
|
autoUpdate: argv['auto-update'] as boolean | undefined,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user