66
77import type { CommandModule } from 'yargs' ;
88import {
9- updateExtensionByName ,
10- updateAllUpdatableExtensions ,
11- type ExtensionUpdateInfo ,
129 loadExtensions ,
1310 annotateActiveExtensions ,
14- checkForAllExtensionUpdates ,
1511} from '../../config/extension.js' ;
1612import { t } from '@thacio/auditaria-cli-core' ;
13+ import {
14+ updateAllUpdatableExtensions ,
15+ type ExtensionUpdateInfo ,
16+ checkForAllExtensionUpdates ,
17+ updateExtension ,
18+ } from '../../config/extensions/update.js' ;
19+ import { checkForExtensionUpdate } from '../../config/extensions/github.js' ;
1720import { getErrorMessage } from '../../utils/errors.js' ;
21+ import { ExtensionUpdateState } from '../../ui/state/extensions.js' ;
1822
1923interface UpdateArgs {
2024 name ?: string ;
@@ -46,7 +50,7 @@ export async function handleUpdate(args: UpdateArgs) {
4650 let updateInfos = await updateAllUpdatableExtensions (
4751 workingDir ,
4852 extensions ,
49- await checkForAllExtensionUpdates ( extensions , ( _ ) => { } ) ,
53+ await checkForAllExtensionUpdates ( extensions , new Map ( ) , ( _ ) => { } ) ,
5054 ( ) => { } ,
5155 ) ;
5256 updateInfos = updateInfos . filter (
@@ -68,13 +72,50 @@ export async function handleUpdate(args: UpdateArgs) {
6872 }
6973 if ( args . name )
7074 try {
75+ const extension = extensions . find (
76+ ( extension ) => extension . name === args . name ,
77+ ) ;
78+ if ( ! extension ) {
79+ console . log (
80+ t (
81+ 'commands.extensions.update.extension_not_found' ,
82+ `Extension "${ args . name } " not found.` ,
83+ { name : args . name } ,
84+ ) ,
85+ ) ;
86+ return ;
87+ }
88+ let updateState : ExtensionUpdateState | undefined ;
89+ if ( ! extension . installMetadata ) {
90+ console . log (
91+ t (
92+ 'commands.extensions.update.missing_install_metadata' ,
93+ `Unable to install extension "${ args . name } " due to missing install metadata` ,
94+ { name : args . name } ,
95+ ) ,
96+ ) ;
97+ return ;
98+ }
99+ await checkForExtensionUpdate ( extension , ( newState ) => {
100+ updateState = newState ;
101+ } ) ;
102+ if ( updateState !== ExtensionUpdateState . UPDATE_AVAILABLE ) {
103+ console . log (
104+ t (
105+ 'commands.extensions.update.already_up_to_date' ,
106+ `Extension "${ args . name } " is already up to date.` ,
107+ { name : args . name } ,
108+ ) ,
109+ ) ;
110+ return ;
111+ }
71112 // TODO(chrstnb): we should list extensions if the requested extension is not installed.
72- const updatedExtensionInfo = await updateExtensionByName (
73- args . name ,
113+ const updatedExtensionInfo = ( await updateExtension (
114+ extension ,
74115 workingDir ,
75- extensions ,
116+ updateState ,
76117 ( ) => { } ,
77- ) ;
118+ ) ) ! ;
78119 if (
79120 updatedExtensionInfo . originalVersion !==
80121 updatedExtensionInfo . updatedVersion
@@ -84,7 +125,7 @@ export async function handleUpdate(args: UpdateArgs) {
84125 console . log (
85126 t (
86127 'commands.extensions.update.already_up_to_date' ,
87- `Extension "${ args . name } " already up to date.` ,
128+ `Extension "${ args . name } " is already up to date.` ,
88129 { name : args . name } ,
89130 ) ,
90131 ) ;
0 commit comments