| 28 | // ─── arg parsing ───────────────────────────────────────────────────────────── |
| 29 | |
| 30 | function parseArgs(argv) { |
| 31 | const args = { _: [], threshold: 0.02, json: false }; |
| 32 | for (let i = 2; i < argv.length; i++) { |
| 33 | const a = argv[i]; |
| 34 | if (a === '--threshold' || a === '-t') { |
| 35 | args.threshold = parseFloat(argv[++i]); |
| 36 | } else if (a === '--json') { |
| 37 | args.json = true; |
| 38 | } else if (a === '--help' || a === '-h') { |
| 39 | args.help = true; |
| 40 | } else if (a.startsWith('--')) { |
| 41 | console.error(`unknown flag: ${a}`); |
| 42 | process.exit(3); |
| 43 | } else { |
| 44 | args._.push(a); |
| 45 | } |
| 46 | } |
| 47 | if (!Number.isFinite(args.threshold)) args.threshold = 0.02; |
| 48 | return args; |
| 49 | } |
| 50 | |
| 51 | function usage() { |
| 52 | console.log('Usage: node bench/diff.js <baseline> <feature> [--threshold 0.02] [--json]'); |