import { rnxExit } from '../run-rnx' import { runScreenshotMode } from './screenshot-mode' import { runThreeMode } from './three-mode' interface ModeOptions { port?: number verbose?: boolean } const VALUE_FLAGS = new Set(['--sim', '--port', '-p']) const SUBCOMMANDS = new Set(['screenshot', 'three']) function findSubcommand(args: string[]): { name: string; index: number } | null { for (let i = 0; i < args.length; i++) { const arg = args[i] if (arg.startsWith('-')) { if (VALUE_FLAGS.has(arg)) i++ continue } return SUBCOMMANDS.has(arg) ? { name: arg, index: i } : null } return null } function withoutSubcommand(args: string[], index: number): string[] { return [...args.slice(0, index), ...args.slice(index + 1)] } function printHelp(): void { console.log(` rnx mode — toggle live display modes usage: rnx mode screenshot [on|off|toggle] rnx mode three [on|off|toggle] rnx mode three configure [options] `) } export async function runMode(args: string[], opts: ModeOptions): Promise { if (args.includes('--help') || args.includes('-h')) { printHelp() return } const sub = findSubcommand(args) if (!sub) { printHelp() rnxExit(1) } const rest = withoutSubcommand(args, sub.index) if (sub.name === 'screenshot') { await runScreenshotMode(rest, opts) return } await runThreeMode(rest, opts) }