import { Command } from 'commander' import { resolveVersionPattern, updateLockFileFromImage } from '../lib/common' import { loadConfig } from '../lib/config' import { processImage } from '../lib/operations' /** * Command to install OCI images from configuration without checking for updates */ export async function cmdInstall(options: { imageName?: string }): Promise { try { const config = loadConfig() const imageNames = Object.keys(config) // Validate configuration if (imageNames.length === 0) { console.error('No configured images found in zzup.yaml') console.log( 'Please create or edit your zzup.yaml file to add image configurations' ) return 1 } // Filter by specific image if provided const imagesToInstall = options.imageName ? imageNames.filter(name => name === options.imageName) : imageNames if (options.imageName && imagesToInstall.length === 0) { console.error(`Image "${options.imageName}" not found in configuration`) return 1 } console.log(`Installing from OCI images...`) console.log( `Found ${imagesToInstall.length} configured image(s) to install\n` ) for (const imageName of imagesToInstall) { const imageConfig = config[imageName] const configuredTag = imageConfig.tag console.log(`\nProcessing image: ${imageName}:${configuredTag}`) // Resolve version pattern to an actual tag const actualTag = await resolveVersionPattern(imageName, configuredTag) // For the zondax/zzup-make image, adjust the sourceDir to include the .payload prefix let sourceDir = imageConfig.sourceDir if ( imageName === 'zondax/zzup-make' && sourceDir && !sourceDir.startsWith('.payload/') ) { sourceDir = `.payload/${sourceDir}` console.log(`Adjusting source directory path to: ${sourceDir}`) } try { // Pass the source and target directories as optional parameters // They will override the manifest values if present await processImage( imageName, actualTag, sourceDir, imageConfig.targetDir ) // Update lock file with the new image details await updateLockFileFromImage(imageName, actualTag) } catch (error) { // Don't repeat the error message, it's already logged in processImage return 1 } } console.log('\n✅ Installation completed successfully!') return 0 } catch (error) { console.error(`Error during installation: ${error}`) return 1 } } /** * Function to configure the install command */ export function configureInstallCommand(command: Command): Command { return command.option( '--image-name ', 'Name of a specific image to install' ) }