{"record":{"id":"381af2ce1fce3fd8","repo":"JuliusBrussee/caveman","slug":"usage-invokedcommand-audit-import-format","errorCode":null,"errorMessage":"usage: ${invokedCommand(\"audit\")} import --format <fmt> <file>","messagePattern":"usage: (.+?) import --format <fmt> <file>","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":17576,"sourceCode":"  const body = await post(`/api/v1/projects/${await projectId()}/keys`, { name: flagFrom(argv, \"--name\", \"cli-key\"), scopes: [\"proxy:write\", \"sdk:write\"] });\n  print(body);\n}\n\nasync function audit(argv: string[]) {\n  if (argv[0] === \"import\") return auditImport(argv);\n  if (argv[0] === \"eval-import\") return auditEvalImport(argv);\n  if (argv[0] === \"report\") return get(`/api/v1/audits/${argv[1] ?? \"aud_demo\"}`).then(print);\n  return post(\"/api/v1/audits\", { last: flagFrom(argv, \"--last\", \"7d\") }).then(print);\n}\n\n// auditImport reads a telemetry export file and POSTs it to /api/v1/imports.\n// Usage: caveman audit import --format <fmt> <file> [--field-map <json>]\n// The org/project scope is resolved server-side from the auth token — never\n// from the file (tenant-scoped rule).\nasync function auditImport(argv: string[]) {\n  const format = flagFrom(argv, \"--format\", \"caveman-jsonl\");\n  const file = positionalAfterOptions(argv.slice(1), new Set([\"--format\", \"--field-map\"]));\n  if (!file) throw new Error(`usage: ${invokedCommand(\"audit\")} import --format <fmt> <file>`);\n  const data = await readFile(file);\n  const cfg = await config();\n  const headers: Record<string, string> = {\n    authorization: `Bearer ${cfg.token}`,\n    \"content-type\": \"application/octet-stream\",\n    \"x-cave-csrf\": \"cli\"\n  };\n  const fieldMap = flagFrom(argv, \"--field-map\", \"\");\n  if (fieldMap) headers[\"x-cave-field-map\"] = fieldMap;\n  const response = await fetch(`${cfg.baseURL}/api/v1/imports?format=${encodeURIComponent(format)}`, {\n    method: \"POST\",\n    headers,\n    body: data\n  });\n  print(await response.json());\n}\n\n// auditEvalImport turns newline-delimited, source-neutral eval records into one","sourceCodeStart":17558,"sourceCodeEnd":17594,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L17558-L17594","documentation":"`auditImport` requires a file positional argument after options. `positionalAfterOptions` returns nothing when no positional file is present, so the CLI throws a usage error telling the exact expected form `caveman audit import --format <fmt> <file>`.","triggerScenarios":"Running `caveman audit import --format caveman-jsonl` (or with no arguments at all) without supplying the input file path as the trailing positional argument.","commonSituations":"Copy-pasting a command and dropping the file argument; putting the file path before the options in an order the parser rejects; forgetting the file because the format flag was supplied.","solutions":["Append the file path as the final positional argument: `caveman audit import --format caveman-jsonl ./events.jsonl`.","Run `caveman audit import` with no args to see usage and confirm argument order.","Ensure the file path is quoted if it contains spaces."],"exampleFix":"// before (shell)\ncaveman audit import --format caveman-jsonl\n// error: usage: caveman audit import --format <fmt> <file>\n// after (shell)\ncaveman audit import --format caveman-jsonl ./audit-events.jsonl","handlingStrategy":"validation","validationCode":"// shell\n[ $# -ge 1 ] && [ -f \"$1\" ] || { echo \"usage: caveman audit import --format <fmt> <file>\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always put the file path last in the command line.","Quote file paths containing spaces.","Test the import command with a small sample file before CI use."],"tags":["cli","usage","audit","missing-argument"],"backgroundTag":"missing-cli-argument","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}