UNPKG

amaran-light-cli

Version:

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

72 lines 3.12 kB
import { writeFile } from 'node:fs/promises'; import chalk from 'chalk'; import { CURVE_HELP_TEXT } from '../../daylightSimulation/constants.js'; import { ScheduleMaker } from '../../daylightSimulation/scheduleMaker.js'; import { textSchedule } from '../../daylightSimulation/textSchedule.js'; export function registerPrintSchedule(program, deps) { const { asyncCommand } = deps; program .command('print') .description('Preview auto-cct schedule from sunrise to sunset') .option('-y, --lat <latitude>', 'Manual latitude (-90 to 90)') .option('-x, --lon <longitude>', 'Manual longitude (-180 to 180)') .option('-d, --date <date>', 'Date to preview (ISO format, e.g., 2025-10-26)') .option('-i, --interval <minutes>', 'Minutes between schedule entries (default: 30)', '30') .option('-C, --curve <curve>', CURVE_HELP_TEXT, 'all') .option('-L, --max-lux <value>', 'Simulation peak in lux (scales the whole day)') .option('-c, --csv', 'Output as CSV format') .option('-o, --output <file>', 'Output result to a file') .option('--cloud-cover <value>', 'Cloud cover (0-1)') .option('--precipitation <type>', 'Precipitation type') .option('--privacy-off', 'Show full IP address and precise coordinates', false) .action(asyncCommand(handlePrintSchedule(deps))); } function handlePrintSchedule(deps) { return async (options) => { const maker = new ScheduleMaker(deps); let schedule; try { schedule = await maker.makeSchedule({ lat: options.lat, lon: options.lon, date: options.date, intervalMinutes: parseInt(options.interval ?? '30', 10), curves: options.curve, includeSpecialTimes: true, cloudCover: options.cloudCover, precipitation: options.precipitation, maxLuxLimit: options.maxLux ? parseFloat(options.maxLux) : undefined, }); } catch (error) { console.error(chalk.red(error.message)); process.exit(1); } const output = textSchedule(schedule, { csv: options.csv, privacyOff: options.privacyOff, interval: options.interval, }); if (options.output) { try { const cleanOutput = textSchedule(schedule, { csv: options.csv, privacyOff: options.privacyOff, interval: options.interval, stripAnsi: true, }); await writeFile(options.output, cleanOutput); console.log(chalk.green(`Schedule saved to ${options.output}`)); } catch (error) { console.error(chalk.red(`Failed to write to file: ${error.message}`)); process.exit(1); } } else { console.log(output); } }; } export default registerPrintSchedule; //# sourceMappingURL=printSchedule.js.map