refakts
Version:
TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.
44 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectCommand = void 0;
const output_handler_1 = require("../services/selection/output-handler");
const ast_service_1 = require("../services/ast-service");
const selection_strategy_factory_1 = require("../strategies/selection-strategy-factory");
class SelectCommand {
constructor() {
this.name = 'select';
this.description = 'Find code elements and return their locations with content preview';
this.complete = true;
this.astService = new ast_service_1.ASTService();
this.strategyFactory = new selection_strategy_factory_1.SelectionStrategyFactory();
this.outputHandler = new output_handler_1.SelectOutputHandler();
}
async execute(file, options) {
try {
const strategy = this.strategyFactory.getStrategy(options);
strategy.validateOptions(options);
await this.performSelection(file, options, strategy);
}
catch (error) {
this.handleExecutionError(error);
}
}
async performSelection(file, options, strategy) {
const sourceFile = this.astService.loadSourceFile(file);
const results = await strategy.select(sourceFile, options);
this.outputHandler.outputResults(results);
}
handleExecutionError(error) {
process.stderr.write(`Error: ${error}\n`);
process.exit(1);
}
validateOptions(options) {
const strategy = this.strategyFactory.getStrategy(options);
strategy.validateOptions(options);
}
getHelpText() {
return '\nExamples:\n refakts select src/file.ts --regex "tempResult"\n refakts select src/file.ts --regex "calculateTotal" --include-definition\n refakts select src/file.ts --regex "tempResult" --include-line\n refakts select src/file.ts --regex "tempResult" --preview-line\n refakts select src/file.ts --range --start-regex "const.*=" --end-regex "return.*"\n refakts select src/file.ts --regex "user.*" --boundaries "function"\n refakts select src/file.ts --structural --regex ".*[Uu]ser.*" --include-methods --include-fields';
}
}
exports.SelectCommand = SelectCommand;
//# sourceMappingURL=select-command.js.map