import { CLICommand } from "../cli/CLICommand.js"; import { parseTodoFile, writeTodoFile } from "../file.js"; import { getCurrentBranch, commitFile } from "../git.js"; export class CreateCommand extends CLICommand { name = "create"; help = "Create a new issue"; description = "Add an issue to the TODO file (must be on develop)"; addArguments(yargs) { return yargs .option("type", { alias: "t", type: "string", choices: ["feature", "bugfix", "hotfix"], demandOption: true, }) .option("title", { type: "string", demandOption: true, }) .option("priority", { alias: "p", type: "string", choices: ["low", "medium", "high"], default: "medium", }) .option("plan", { type: "string", demandOption: true, description: "Description of what needs to be done", }) .option("module", { alias: "m", type: "string", }); } async execute(args) { const branch = getCurrentBranch(); if (branch !== "develop") { console.error(`Must be on develop to create issues (currently on ${branch})`); return 1; } const todo = await parseTodoFile(); const mod = args.module; if (mod && todo.modules) { const valid = todo.modules.map(m => m.name); if (!valid.includes(mod)) { console.error(`Module "${mod}" not defined. Valid: ${valid.join(", ")}`); return 1; } } const nextId = todo.issues.length > 0 ? Math.max(...todo.issues.map(i => i.id)) + 1 : 1; const today = new Date().toISOString().slice(0, 10); todo.issues.push({ id: nextId, type: args.type, title: args.title, status: "open", priority: args.priority, created: today, module: mod, relationships: {}, description: args.plan, body: "", }); writeTodoFile(todo); commitFile("TODO", `todo(${nextId}): open`); console.log(`Created issue #${nextId}: ${args.title}`); return 0; } }