UNPKG

simple-task-master

Version:
68 lines 2.63 kB
"use strict"; /** * Delete task command */ Object.defineProperty(exports, "__esModule", { value: true }); exports.deleteCommand = void 0; const commander_1 = require("commander"); const task_manager_1 = require("../lib/task-manager"); const output_1 = require("../lib/output"); const errors_1 = require("../lib/errors"); /** * Validate that no other tasks depend on the target task */ async function validateNoDependents(taskManager, taskId) { const allTasks = await taskManager.list(); const dependents = allTasks.filter((task) => task.dependencies?.includes(parseInt(taskId)) || // eslint-disable-next-line @typescript-eslint/no-explicit-any task.depends_on?.includes(taskId) // Handle unknown fields ); if (dependents.length > 0) { const dependentTitles = dependents.map((t) => `${t.id}: ${t.title}`).join(', '); throw new errors_1.ValidationError(`Cannot delete task: ${dependents.length} task(s) depend on it (${dependentTitles}). Use --force to delete anyway.`); } } /** * Delete a task */ async function deleteTask(idStr, options) { try { const taskManager = await task_manager_1.TaskManager.create(); // Parse task ID const id = parseInt(idStr, 10); if (isNaN(id) || id <= 0) { throw new errors_1.ValidationError(`Invalid task ID: ${idStr}`); } // Get the task first to verify it exists and show what will be deleted const task = await taskManager.get(id); // Check for dependencies unless --force is used if (!options.force) { await validateNoDependents(taskManager, idStr); } // Perform the deletion await taskManager.delete(id); (0, output_1.printSuccess)(`Deleted task ${id}: "${task.title}"`); } catch (error) { if (error instanceof errors_1.ValidationError || error instanceof errors_1.FileSystemError || error instanceof errors_1.ConfigurationError || error instanceof errors_1.NotFoundError || error instanceof Error) { (0, output_1.printError)(error.message); process.exit(error instanceof errors_1.NotFoundError ? 3 : 1); } throw error; } } /** * Create the delete command */ exports.deleteCommand = new commander_1.Command('delete') .description('Delete a task permanently') .argument('<id>', 'Task ID to delete') .option('-f, --force', 'Force deletion even if other tasks depend on it') .action(async (id, options) => { await deleteTask(id, options); }); //# sourceMappingURL=delete.js.map