UNPKG

refakts

Version:

TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.

82 lines 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RoadmapCLI = void 0; const roadmap_service_1 = require("./roadmap-service"); const roadmap_display_1 = require("./roadmap-display"); class RoadmapCLI { constructor() { this.service = new roadmap_service_1.RoadmapService(); this.display = new roadmap_display_1.RoadmapDisplay(); } handleCommand(command, args) { const commandHandler = this.getCommandHandler(command, args); if (commandHandler) { commandHandler(); } else { this.showUsage(); } } getCommandHandler(command, args) { const commandMap = { 'vote': () => this.handleVoteCommand(args), 'add': () => this.handleAddCommand(args), 'remove': () => this.handleRemoveCommand(args), 'status': () => this.handleStatusCommand() }; return commandMap[command]; } showUsage() { process.stderr.write('Usage: npm run roadmap:vote|add|remove|status\n'); process.exit(1); } handleVoteCommand(args) { if (!args[1]) { process.stderr.write('Usage: npm run roadmap:vote <feature-name>\n'); process.exit(1); } this.service.vote(args[1]); } handleAddCommand(args) { const addArgs = this.parseAddArguments(args); this.service.add(addArgs.name, addArgs.description, addArgs.why); } handleRemoveCommand(args) { if (!args[1]) { process.stderr.write('Usage: npm run roadmap:remove <feature-name>\n'); process.exit(1); } this.service.remove(args[1]); } handleStatusCommand() { const data = this.service.getRoadmapData(); this.display.showStatus(data); } parseAddArguments(args) { const indices = this.extractArgumentIndices(args); this.validateRequiredArguments(indices, args); return { name: args[indices.nameIndex + 1], description: args[indices.descIndex + 1], why: this.extractOptionalWhy(indices.whyIndex, args) }; } extractArgumentIndices(args) { return { nameIndex: args.indexOf('--feature'), descIndex: args.indexOf('--description'), whyIndex: args.indexOf('--why') }; } validateRequiredArguments(indices, args) { if (indices.nameIndex === -1 || !args[indices.nameIndex + 1] || indices.descIndex === -1 || !args[indices.descIndex + 1]) { process.stderr.write('Usage: npm run roadmap:add --feature <name> --description <desc> [--why <reason>]\n'); process.exit(1); } } extractOptionalWhy(whyIndex, args) { return whyIndex !== -1 && args[whyIndex + 1] ? args[whyIndex + 1] : undefined; } } exports.RoadmapCLI = RoadmapCLI; //# sourceMappingURL=roadmap-cli.js.map