UNPKG

scai

Version:

> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.

51 lines (50 loc) 2.28 kB
// File: src/commands/delete.ts import readline from 'readline'; import { Config, writeConfig } from '../config.js'; import chalk from 'chalk'; export async function runInteractiveDelete() { const config = Config.getRaw(); const keys = Object.keys(config.repos || {}); if (!keys.length) { console.log('⚠️ No repositories configured.'); return; } console.log('\n🗑️ Repositories Available for Deletion:\n'); keys.forEach((key, i) => { const isActive = config.activeRepo === key ? chalk.green('(active)') : ''; const dir = config.repos[key]?.indexDir ?? ''; console.log(`${chalk.blue(`${i + 1})`)} ${key} ${isActive}`); console.log(` ↳ ${chalk.grey(dir)}`); }); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.question('\n👉 Select a repository number to delete: ', (answer) => { rl.close(); const index = parseInt(answer.trim(), 10) - 1; if (isNaN(index) || index < 0 || index >= keys.length) { console.log('❌ Invalid selection.'); return; } const selectedKey = keys[index]; console.log(`\n⚠️ Deleting repository: ${chalk.red(selectedKey)}\n`); // Build an update that uses the null-sentinel for deletion. const update = { repos: { [selectedKey]: null } }; // If deleting the active repo, pick another one (first remaining) or unset. if (config.activeRepo === selectedKey) { const remainingKeys = keys.filter(k => k !== selectedKey); update.activeRepo = remainingKeys[0] || undefined; console.log(`ℹ️ Active repo reset to: ${chalk.green(update.activeRepo ?? 'none')}`); } try { writeConfig(update); // this will actually remove the repo key console.log(`✅ Repository "${selectedKey}" removed from config.json.`); // NOTE: We intentionally do NOT delete the on-disk repo folder here. // Only remove data when a --purge flag is explicitly used. } catch (err) { console.error('❌ Failed to update config.json:', err instanceof Error ? err.message : err); } }); }