mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-30 23:14:32 -07:00
Add support for auto-updating git extensions (#8511)
This commit is contained in:
@@ -6,14 +6,18 @@
|
||||
|
||||
import type { CommandModule } from 'yargs';
|
||||
import {
|
||||
updateExtensionByName,
|
||||
updateAllUpdatableExtensions,
|
||||
type ExtensionUpdateInfo,
|
||||
loadExtensions,
|
||||
annotateActiveExtensions,
|
||||
checkForAllExtensionUpdates,
|
||||
} from '../../config/extension.js';
|
||||
import {
|
||||
updateAllUpdatableExtensions,
|
||||
type ExtensionUpdateInfo,
|
||||
checkForAllExtensionUpdates,
|
||||
updateExtension,
|
||||
} from '../../config/extensions/update.js';
|
||||
import { checkForExtensionUpdate } from '../../config/extensions/github.js';
|
||||
import { getErrorMessage } from '../../utils/errors.js';
|
||||
import { ExtensionUpdateState } from '../../ui/state/extensions.js';
|
||||
|
||||
interface UpdateArgs {
|
||||
name?: string;
|
||||
@@ -37,7 +41,7 @@ export async function handleUpdate(args: UpdateArgs) {
|
||||
let updateInfos = await updateAllUpdatableExtensions(
|
||||
workingDir,
|
||||
extensions,
|
||||
await checkForAllExtensionUpdates(extensions, (_) => {}),
|
||||
await checkForAllExtensionUpdates(extensions, new Map(), (_) => {}),
|
||||
() => {},
|
||||
);
|
||||
updateInfos = updateInfos.filter(
|
||||
@@ -54,13 +58,34 @@ export async function handleUpdate(args: UpdateArgs) {
|
||||
}
|
||||
if (args.name)
|
||||
try {
|
||||
// TODO(chrstnb): we should list extensions if the requested extension is not installed.
|
||||
const updatedExtensionInfo = await updateExtensionByName(
|
||||
args.name,
|
||||
workingDir,
|
||||
extensions,
|
||||
() => {},
|
||||
const extension = extensions.find(
|
||||
(extension) => extension.name === args.name,
|
||||
);
|
||||
if (!extension) {
|
||||
console.log(`Extension "${args.name}" not found.`);
|
||||
return;
|
||||
}
|
||||
let updateState: ExtensionUpdateState | undefined;
|
||||
if (!extension.installMetadata) {
|
||||
console.log(
|
||||
`Unable to install extension "${args.name}" due to missing install metadata`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
await checkForExtensionUpdate(extension, (newState) => {
|
||||
updateState = newState;
|
||||
});
|
||||
if (updateState !== ExtensionUpdateState.UPDATE_AVAILABLE) {
|
||||
console.log(`Extension "${args.name}" is already up to date.`);
|
||||
return;
|
||||
}
|
||||
// TODO(chrstnb): we should list extensions if the requested extension is not installed.
|
||||
const updatedExtensionInfo = (await updateExtension(
|
||||
extension,
|
||||
workingDir,
|
||||
updateState,
|
||||
() => {},
|
||||
))!;
|
||||
if (
|
||||
updatedExtensionInfo.originalVersion !==
|
||||
updatedExtensionInfo.updatedVersion
|
||||
@@ -69,7 +94,7 @@ export async function handleUpdate(args: UpdateArgs) {
|
||||
`Extension "${args.name}" successfully updated: ${updatedExtensionInfo.originalVersion} → ${updatedExtensionInfo.updatedVersion}.`,
|
||||
);
|
||||
} else {
|
||||
console.log(`Extension "${args.name}" already up to date.`);
|
||||
console.log(`Extension "${args.name}" is already up to date.`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(getErrorMessage(error));
|
||||
|
||||
Reference in New Issue
Block a user