/** * Backup Name Command * Set or view a human-readable name/annotation on a backup. * * Usage: * celilo backup name Set a name * celilo backup name Show current name * celilo backup name --clear Remove the name */ import { formatSize, getBackup, updateBackupName } from '../../services/backup-metadata'; import { celiloIntro, celiloOutro } from '../prompts'; import type { CommandResult } from '../types'; export async function handleBackupName( args: string[], flags: Record = {}, ): Promise { try { const backupId = args[0]; if (!backupId) { return { success: false, error: 'Backup ID is required\n\nUsage:\n celilo backup name \n celilo backup name --clear', }; } const backup = getBackup(backupId); if (!backup) { return { success: false, error: `Backup not found: ${backupId}` }; } const shortId = backup.id.substring(0, 8); // Clear the name if (flags.clear) { celiloIntro('Clear Backup Name'); updateBackupName(backup.id, null); celiloOutro(`Name cleared for backup ${shortId}.`); return { success: true, message: `Cleared name for ${shortId}` }; } // Remaining args after the backup ID form the name const nameParts = args.slice(1); // No name provided — show current name if (nameParts.length === 0) { celiloIntro('Backup Name'); const module = backup.backupType === 'system_state' ? '[system]' : (backup.moduleId ?? 'unknown'); console.log(''); console.log(` Backup: ${shortId} (${module}, ${formatSize(backup.sizeBytes)})`); console.log(` Name: ${backup.name ?? '(none)'}`); console.log(''); return { success: true, message: backup.name ?? '(none)' }; } // Set the name (join all remaining args — supports both quoted and unquoted) const name = nameParts.join(' '); celiloIntro('Set Backup Name'); updateBackupName(backup.id, name); celiloOutro(`Backup ${shortId} named: "${name}"`); return { success: true, message: `Named ${shortId}: ${name}` }; } catch (error) { return { success: false, error: `Failed to update backup name: ${error instanceof Error ? error.message : String(error)}`, }; } }