{"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":"validation","errorClass":null,"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/27111382b4a79a7e983289d6e983a06af185ed0f/packages/cap-vite/src/cli.ts#L26-L62","documentation":"parseCapViteCliArgs requires the argv to contain a literal '--' separator that divides Vite args (left) from Capacitor args (right). When no '--' is present, the function throws the usage string. This is a deliberate contract: cap-vite wraps Vite and forwards extra args to `cap run`, so the boundary must be explicit.","triggerScenarios":"Running `cap-vite ios` (forgot the --); running `cap-vite build` with no separator because the user assumed Vite-style flags; argv sliced incorrectly before calling parseCapViteCliArgs so the separator was dropped.","commonSituations":"New users unfamiliar with the required `--` syntax; npm scripts that pass through arguments without preserving the separator; tooling that consumes `--` itself (npm/pnpm use -- to separate too, leading to double-separator confusion).","solutions":["Use the documented form: `cap-vite [vite args] -- <ios|android> [cap args]`.","When invoking through pnpm/npm, remember the package manager also consumes a `--`, so you may need two: `pnpm cap-vite -- -- ios`.","Print usage (argv[0] === '--help') when unsure rather than guessing."],"exampleFix":"# before\ncap-vite ios\n\n# after\ncap-vite -- ios\n# or, via pnpm:\npnpm cap-vite -- -- ios","handlingStrategy":"validation","validationCode":"if (!argv.includes('--')) {\n  console.error('Usage: cap-vite [vite args...] -- <ios|android> [cap run args...]')\n  process.exit(1)\n}","typeGuard":"function hasSeparator(argv: string[]): argv is string[] & { __sep: true } {\n  return argv.includes('--')\n}","tryCatchPattern":"try {\n  return parseCapViteCliArgs(argv)\n}\ncatch (err) {\n  if ((err as Error).message.startsWith('cap-vite')) {\n    printHelp()\n    process.exit(1)\n  }\n  throw err\n}","preventionTips":["Always separate Vite args from Capacitor args with a literal '--'.","Remember pnpm/npm also consume a '--', so add an extra one when running through them.","Print --help when unsure of the syntax."],"tags":["cli","argv","capacitor","validation","usage"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}