UNPKG

amaran-light-cli

Version:

Command line tool for controlling Aputure Amaran lights via WebSocket to a local Amaran desktop app.

43 lines 1.5 kB
import chalk from 'chalk'; /** * Adds standard options to a commander command */ export function addStandardOptions(command) { return command .option('-u, --url <url>', 'WebSocket URL') .option('-c, --client-id <id>', 'Client ID') .option('-d, --debug', 'Enable debug mode'); } /** * Common pattern for connecting, finding devices, executing an action, and disconnecting */ export async function runDeviceAction({ deps, options, deviceQuery, actionName, onSuccess }, action, allAction) { const { createController, findDevice } = deps; const controller = await createController(options.url, options.clientId, options.debug); try { if (!deviceQuery || deviceQuery.toLowerCase() === 'all') { await allAction(controller); return; } const device = findDevice(controller, deviceQuery); if (!device) { console.error(chalk.red(`Device "${deviceQuery}" not found`)); process.exit(1); } if (!device.node_id) { console.error(chalk.red(`Device "${deviceQuery}" has no node_id`)); process.exit(1); } await action(device, controller); if (onSuccess) { console.log(chalk.green(onSuccess(device))); } } catch (error) { console.error(chalk.red(`✗ Failed to ${actionName}: ${error.message}`)); } finally { await controller.disconnect(); } } //# sourceMappingURL=cmdUtils.js.map