{"record":{"id":"224f0776df9cea11","repo":"moeru-ai/airi","slug":"cap-vite-vite-args-ios-android-cap-run","errorCode":null,"errorMessage":"cap-vite [vite args...] -- <ios|android> [cap run args...]","messagePattern":"cap-vite \\[vite args\\.\\.\\.\\] -- <ios\\|android> \\[cap run args\\.\\.\\.\\]","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cap-vite/src/cli.ts","lineNumber":44,"sourceCode":"}\n\nexport function getCapViteCliUsage(): string {\n  return usage\n}\n\n// TODO: CLI and `cap run` argument handling are hand-rolled (see also `resolveCapRunArgs` /\n// `hasCapacitorTargetArg` in native.ts). If parsing rules keep growing, adopt a dedicated argv\n// library (cac is already a dependency—consider subcommands or a small wrapper) so flags like\n// `--target` / `--target=`, env-based defaults, and validation stay in one maintainable layer.\n\nexport function parseCapViteCliArgs(argv: string[]): ParsedCapViteCliArgs | null {\n  if (argv.length === 1 && (argv[0] === '--help' || argv[0] === '-h')) {\n    return null\n  }\n\n  const separatorIndex = argv.indexOf('--')\n  if (separatorIndex === -1) {\n    throw new Error(usage)\n  }\n\n  const capArgs = argv.slice(separatorIndex + 1)\n  if (capArgs.length === 0) {\n    throw new Error(usage)\n  }\n\n  const platform = capArgs[0]\n  if (platform !== 'android' && platform !== 'ios') {\n    throw new Error(usage)\n  }\n\n  return {\n    capArgs,\n    viteArgs: argv.slice(0, separatorIndex),\n  }\n}\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/moeru-ai/airi/blob/677329427f32468c74b17f3ec47eeca4e05bec65/packages/cap-vite/src/cli.ts#L26-L62","documentation":"The cap-vite CLI splits argv at a bare '--': Vite args go before it, `cap run` args after. parseCapViteCliArgs throws the usage string as the error message when argv contains no '--' at all, so the process exits showing exactly how to invoke it.","triggerScenarios":"Running `cap-vite ios` or `cap-vite --host 0.0.0.0` — any invocation without a bare '--' token, e.g. because shell quoting or an npm script swallowed it.","commonSituations":"Muscle memory from `cap run ios` (no separator); npm scripts that forward \"$@\" when no extra args were passed; quoting the separator inside another string.","solutions":["Invoke with the separator: `cap-vite -- ios` or `cap-vite --host 0.0.0.0 --port 5173 -- android`","Run `cap-vite --help` to see the exact usage and examples","In npm scripts, keep the '--' literal: \"cap-vite -- ios\""],"exampleFix":"# before\n$ cap-vite ios   # Error: cap-vite [vite args...] -- <ios|android> [cap run args...]\n\n# after\n$ cap-vite -- ios","handlingStrategy":"validation","validationCode":"// Validate before spawning the CLI\nif (!argv.includes('--')) {\n  console.error(`Usage: ${getCapViteUsage()}`)\n  process.exit(1)\n}","typeGuard":null,"tryCatchPattern":"try {\n  const parsed = parseCapViteCliArgs(argv)\n}\ncatch (err) {\n  if (err instanceof Error && err.message.startsWith('cap-vite')) {\n    console.error(getCapViteCliHelpText()) // message IS the usage line\n    process.exit(1)\n  }\n  throw err\n}","preventionTips":["Keep the literal '--' in npm scripts and wrappers that forward args","Print help on parse failure instead of assuming defaults","Remember the shape: vite flags, then '--', then platform + cap run flags"],"tags":["cli","capacitor","usage","arguments"],"backgroundTag":"invalid-cli-argument","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","contentChangedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}