UNPKG

revit-cli

Version:

A scalable CLI tool for Revit communication and data manipulation

200 lines 8.62 kB
"use strict"; /** * Bulk update rooms command implementation * Handles bulk room update operations with filtering */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBulkUpdateRoomsCommand = createBulkUpdateRoomsCommand; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const room_service_js_1 = require("../../services/room-service.js"); const room_utils_js_1 = require("../../utils/room-utils.js"); /** * Creates the update-rooms command for bulk updates * @param getState - Function to get CLI state * @returns Commander command instance */ function createBulkUpdateRoomsCommand(getState) { const command = new commander_1.Command('update-rooms') .description('Update multiple rooms based on filter criteria') .option('-l, --level <level>', 'Filter by level') .option('-d, --department <department>', 'Filter by department') .option('-o, --occupancy <occupancy>', 'Filter by occupancy') .option('-n, --name <pattern>', 'Filter by name pattern (regex)') .option('-r, --number <pattern>', 'Filter by room number pattern (regex)') .option('--min-area <area>', 'Minimum area filter', parseFloat) .option('--max-area <area>', 'Maximum area filter', parseFloat) .option('-f, --filter <filter>', 'Filter string in format "key=value,key2=value2"') .option('-c, --comments <comments>', 'Update room comments') .option('--set-department <department>', 'Update room department') .option('--set-occupancy <occupancy>', 'Update room occupancy') .option('--set-name <name>', 'Update room name') .option('--set-number <number>', 'Update room number') .option('-p, --param <param>', 'Update custom parameter in format "key=value"', collectParams, []) .option('--dry-run', 'Show what would be updated without making changes') .option('--confirm', 'Skip confirmation prompt') .option('--batch-size <size>', 'Process rooms in batches of specified size', parseInt, 10) .action(async (options) => { try { const state = await getState(); await executeBulkUpdateRooms(state.revitConnector, state.logger, options); } catch (error) { const state = await getState(); state.logger.error('Bulk update rooms command failed:', error); console.log(chalk_1.default.red('❌ Failed to update rooms')); process.exit(1); } }); return command; } /** * Collects parameter options into an array * @param value - Current parameter value * @param previous - Previous parameter values * @returns Updated parameter array */ function collectParams(value, previous) { return previous.concat([value]); } /** * Executes the bulk update rooms operation * @param revitConnector - Revit API connector instance * @param logger - Logger instance * @param options - Command options */ async function executeBulkUpdateRooms(revitConnector, logger, options) { const roomService = new room_service_js_1.RoomService(revitConnector, logger); // Build filter options const filter = {}; // Parse individual filter options if (options.level) filter.level = options.level; if (options.department) filter.department = options.department; if (options.occupancy) filter.occupancy = options.occupancy; if (options.name) filter.namePattern = options.name; if (options.number) filter.numberPattern = options.number; if (options.minArea !== undefined) filter.minArea = options.minArea; if (options.maxArea !== undefined) filter.maxArea = options.maxArea; // Parse filter string if provided if (options.filter) { const parsedFilter = (0, room_utils_js_1.parseFilterString)(options.filter); Object.assign(filter, parsedFilter); } // Check if any filters were provided if (Object.keys(filter).length === 0) { console.error('No filter criteria specified. This would update ALL rooms in the project.'); console.error('Please specify at least one filter option to limit the scope.'); console.error('Use --help to see available filter options.'); process.exit(1); } // Build parameters to update const parameters = {}; // Add standard parameters if (options.comments !== undefined) parameters.comments = options.comments; if (options.setDepartment !== undefined) parameters.department = options.setDepartment; if (options.setOccupancy !== undefined) parameters.occupancy = options.setOccupancy; if (options.setName !== undefined) parameters.name = options.setName; if (options.setNumber !== undefined) parameters.number = options.setNumber; // Parse custom parameters if (options.param && options.param.length > 0) { for (const param of options.param) { const [key, ...valueParts] = param.split('='); if (!key || valueParts.length === 0) { console.error(`Invalid parameter format: '${param}'. Use 'key=value' format.`); process.exit(1); } const value = valueParts.join('='); // Rejoin in case value contains '=' parameters[key.trim()] = value.trim(); } } // Check if any parameters were provided if (Object.keys(parameters).length === 0) { console.error('No parameters specified for update. Use --help to see available options.'); process.exit(1); } // Display filter criteria console.log('\nFilter criteria:'); Object.entries(filter).forEach(([key, value]) => { console.log(` ${key}: ${value}`); }); // Display parameters to update console.log('\nParameters to update:'); Object.entries(parameters).forEach(([key, value]) => { console.log(` ${key}: ${value}`); }); // Create bulk update options const bulkOptions = { filter, parameters, dryRun: options.dryRun }; // Perform the bulk update console.log('\nAnalyzing rooms...'); const result = await roomService.bulkUpdateRooms(bulkOptions); // Display results console.log(`\n=== Bulk Update Results ===`); console.log(`Total rooms processed: ${result.totalProcessed}`); console.log(`Successfully updated: ${result.successCount}`); console.log(`Failed updates: ${result.failureCount}`); if (options.dryRun) { console.log('\n[DRY RUN] No actual changes were made.'); if (result.updatedRooms.length > 0) { console.log('\nRooms that would be updated:'); result.updatedRooms.slice(0, 10).forEach((room, index) => { console.log(` ${index + 1}. ${(0, room_utils_js_1.formatRoomForDisplay)(room)}`); }); if (result.updatedRooms.length > 10) { console.log(` ... and ${result.updatedRooms.length - 10} more rooms`); } } } else { // Real update results if (result.successCount > 0) { console.log('\n✅ Successfully updated rooms:'); result.updatedRooms.slice(0, 5).forEach((room, index) => { console.log(` ${index + 1}. ${(0, room_utils_js_1.formatRoomForDisplay)(room)}`); }); if (result.updatedRooms.length > 5) { console.log(` ... and ${result.updatedRooms.length - 5} more rooms`); } } if (result.failureCount > 0) { console.log('\n❌ Failed updates:'); result.errors.slice(0, 5).forEach((error, index) => { console.log(` ${index + 1}. Room ${error.roomId}: ${error.error}`); }); if (result.errors.length > 5) { console.log(` ... and ${result.errors.length - 5} more errors`); } } } // Exit with appropriate code if (!options.dryRun && result.failureCount > 0) { console.log('\n⚠️ Some updates failed. Check the errors above.'); process.exit(1); } else if (result.totalProcessed === 0) { console.log('\n⚠️ No rooms matched the specified filter criteria.'); process.exit(1); } else { console.log('\n✅ Bulk update operation completed successfully.'); } } //# sourceMappingURL=bulk-update-rooms.js.map