import { runProfile } from './profile' import { runReset } from './reset' interface StorageOptions { port?: number verbose?: boolean } const VALUE_FLAGS = new Set(['--sim', '--port', '-p']) const SUBCOMMANDS = new Set(['profile', 'clear']) 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 printHelp(): void { console.log(` rnx storage — manage sim and app storage usage: rnx storage profile rnx storage clear [--full] [--sim ] [--json] subcommands: profile list profile create profile clear profile delete clear clear the current guest app data and relaunch it `) } export async function runStorage(args: string[], opts: StorageOptions): Promise { if (args.includes('--help') || args.includes('-h')) { printHelp() return 0 } const sub = findSubcommand(args) if (sub?.name === 'profile') { return runProfile([...args.slice(0, sub.index), ...args.slice(sub.index + 1)], opts) } if (sub?.name === 'clear') { return runReset([...args.slice(0, sub.index), ...args.slice(sub.index + 1)], opts) } console.error(` unknown storage command: ${sub?.name ?? '(missing)'}`) printHelp() return 1 }