UNPKG

revit-cli

Version:

A scalable CLI tool for Revit communication and data manipulation

141 lines 5.74 kB
"use strict"; /** * Update room command implementation * Handles single room update operations */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createUpdateRoomCommand = createUpdateRoomCommand; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const room_utils_1 = require("../../utils/room-utils"); const room_service_1 = require("../../services/room-service"); /** * Creates the update-room command * @param getState - Function to get CLI state * @returns Commander command instance */ function createUpdateRoomCommand(getState) { const command = new commander_1.Command('update-room') .description('Update a single room with new parameter values') .argument('<roomId>', 'ID of the room to update') .option('-c, --comments <comments>', 'Update room comments') .option('-d, --department <department>', 'Update room department') .option('-o, --occupancy <occupancy>', 'Update room occupancy') .option('-n, --name <name>', 'Update room name') .option('-r, --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') .action(async (roomId, options) => { try { const state = await getState(); await executeUpdateRoom(state.revitConnector, state.logger, roomId, options); } catch (error) { const state = await getState(); state.logger.error('Update room command failed:', error); console.log(chalk_1.default.red('❌ Failed to update room')); 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 update room operation * @param revitConnector - Revit API connector instance * @param logger - Logger instance * @param roomId - ID of the room to update * @param options - Command options */ async function executeUpdateRoom(revitConnector, logger, roomId, options) { const roomService = new room_service_1.RoomService(revitConnector, logger); // First, verify the room exists const existingRoom = await roomService.getRoomById(roomId); if (!existingRoom) { console.error(`Room with ID '${roomId}' not found.`); process.exit(1); } console.log(`\nCurrent room details:`); console.log((0, room_utils_1.formatRoomForDisplay)(existingRoom, true)); // Build parameters to update const parameters = {}; // Add standard parameters if (options.comments !== undefined) parameters.comments = options.comments; if (options.department !== undefined) parameters.department = options.department; if (options.occupancy !== undefined) parameters.occupancy = options.occupancy; if (options.name !== undefined) parameters.name = options.name; if (options.number !== undefined) parameters.number = options.number; // 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 what will be updated console.log(`\nParameters to update:`); Object.entries(parameters).forEach(([key, value]) => { console.log(` ${key}: ${value}`); }); // Dry run mode if (options.dryRun) { console.log(`\n[DRY RUN] Would update room '${existingRoom.name}' (${roomId}) with the above parameters.`); console.log('No actual changes were made.'); return; } // Confirm update console.log(`\nUpdating room '${existingRoom.name}' (${roomId})...`); try { // Perform the update const updateResponse = await roomService.updateRoom(roomId, parameters); if (updateResponse.success) { console.log('✅ Room updated successfully!'); if (updateResponse.room) { console.log(`\nUpdated room details:`); console.log((0, room_utils_1.formatRoomForDisplay)(updateResponse.room, true)); } if (updateResponse.message) { console.log(`\nMessage: ${updateResponse.message}`); } } else { console.error('❌ Room update failed.'); if (updateResponse.error) { console.error(`Error: ${updateResponse.error}`); } process.exit(1); } } catch (error) { console.error('❌ Failed to update room:'); console.error(error instanceof Error ? error.message : 'Unknown error'); process.exit(1); } } //# sourceMappingURL=update-room.js.map