import * as fs from 'fs' import { Command } from 'commander' import { loadConfig, migrateConfigIfNeeded } from '../lib/config' // Simplified command to just list configured image names export async function cmdList(options: { imageName?: string }): Promise { try { const configPath = migrateConfigIfNeeded() // Check if config file exists if (!fs.existsSync(configPath)) { console.log(`No configuration file found at ${configPath}`) console.log('Run "zzup init" to create a new configuration.') return 0 } // Load config const config = loadConfig() // Get image names const imageNames = Object.keys(config) if (imageNames.length === 0) { console.log(`No images configured in ${configPath}`) return 0 } // If specific image name is provided, only show that one if (options.imageName) { if (!config[options.imageName]) { console.error(`Image "${options.imageName}" not found in configuration`) return 1 } process.stdout.write(`${options.imageName}\n`) return 0 } // Simply list all configured image names for (const imageName of imageNames) { process.stdout.write(`${imageName}\n`) } return 0 } catch (error) { console.error(`Error listing images: ${error}`) return 1 } } // Function to configure the list command export function configureListCommand(command: Command): Command { return command.option( '--image-name ', 'Name of a specific image to list' ) }