scai
Version:
> AI-powered CLI tool for commit messages **and** pull request reviews ā using local models.
51 lines (50 loc) ⢠2.28 kB
JavaScript
// 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);
}
});
}