import { DaikinFactory } from '../src/factory.js'; interface CliArgs { ip: string | null; key: string | null; password: string | null; help: boolean; } export function parseArgs(): CliArgs { const args = process.argv.slice(2); const result: CliArgs = { ip: null, key: null, password: null, help: false, }; for (let i = 0; i < args.length; i++) { const arg = args[i]; switch (arg) { case '-i': case '--ip': result.ip = args[++i] || null; break; case '-k': case '--key': result.key = args[++i] || null; break; case '-p': case '--password': result.password = args[++i] || null; break; case '-h': case '--help': result.help = true; break; } } return result; } export async function getDeviceFromArgs(): Promise> { const args = parseArgs(); if (args.help) { printUsage(); process.exit(0); } let ip = args.ip; if (!ip) { ip = await promptInput('Enter device IP address: '); } const options: { key?: string; password?: string } = {}; if (args.key) { options.key = args.key; } else if (args.password) { options.password = args.password; } console.log(`\nConnecting to Daikin device at ${ip}...`); const device = await DaikinFactory(ip, options); return device; } export async function promptInput(message: string): Promise { const readline = await import('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); return new Promise((resolve) => { rl.question(message, (answer) => { rl.close(); resolve(answer.trim()); }); }); } export async function promptConfirm(message: string): Promise { const readline = await import('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); return new Promise((resolve) => { rl.question(`${message} (y/n) `, (answer) => { rl.close(); resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === ''); }); }); } export function printUsage(): void { console.log(` Usage: tsx scripts/