|
1 | 1 | #!/usr/bin/env node |
2 | 2 | |
3 | 3 | import { execFileSync } from "node:child_process"; |
| 4 | +import { parsePositiveInt } from "./lib/numeric-options.mjs"; |
4 | 5 | |
5 | 6 | const DEFAULT_GITHUB_REPOSITORY = "openclaw/openclaw"; |
6 | 7 | const RUN_JOBS_PAGE_SIZE = 20; |
@@ -337,31 +338,58 @@ function printSection(title, jobs, metric) {
|
337 | 338 | } |
338 | 339 | |
339 | 340 | export function parseRunTimingArgs(args) { |
340 | | -const recentIndex = args.indexOf("--recent"); |
341 | | -const limitIndex = args.indexOf("--limit"); |
342 | | -const ignoredArgIndexes = new Set(); |
343 | | -for (const [index, arg] of args.entries()) { |
344 | | -if (arg === "--" || arg === "--latest-main") { |
345 | | -ignoredArgIndexes.add(index); |
| 341 | +let explicitRunId; |
| 342 | +let limit = 15; |
| 343 | +let recentLimit = null; |
| 344 | +let useLatestMain = false; |
| 345 | + |
| 346 | +for (let index = 0; index < args.length; index += 1) { |
| 347 | +const arg = args[index]; |
| 348 | +if (arg === "--") { |
| 349 | +continue; |
346 | 350 | } |
| 351 | +if (arg === "--latest-main") { |
| 352 | +useLatestMain = true; |
| 353 | +continue; |
| 354 | +} |
| 355 | +const limitOption = consumePositiveIntFlag(args, index, "--limit"); |
| 356 | +if (limitOption) { |
| 357 | +limit = limitOption.value; |
| 358 | +index = limitOption.nextIndex; |
| 359 | +continue; |
| 360 | +} |
| 361 | +const recentOption = consumePositiveIntFlag(args, index, "--recent"); |
| 362 | +if (recentOption) { |
| 363 | +recentLimit = recentOption.value; |
| 364 | +index = recentOption.nextIndex; |
| 365 | +continue; |
| 366 | +} |
| 367 | +explicitRunId ??= arg; |
347 | 368 | } |
348 | | -if (limitIndex !== -1) { |
349 | | -ignoredArgIndexes.add(limitIndex); |
350 | | -ignoredArgIndexes.add(limitIndex + 1); |
351 | | -} |
352 | | -if (recentIndex !== -1) { |
353 | | -ignoredArgIndexes.add(recentIndex); |
354 | | -ignoredArgIndexes.add(recentIndex + 1); |
355 | | -} |
356 | | -const limit = |
357 | | -limitIndex === -1 ? 15 : Math.max(1, Number.parseInt(args[limitIndex + 1] ?? "", 10) || 15); |
358 | | -const recentLimit = |
359 | | -recentIndex === -1 ? null : Math.max(1, Number.parseInt(args[recentIndex + 1] ?? "", 10) || 10); |
| 369 | + |
360 | 370 | return { |
361 | | -explicitRunId: args.find((_arg, index) => !ignoredArgIndexes.has(index)), |
| 371 | + explicitRunId, |
362 | 372 | limit, |
363 | 373 | recentLimit, |
364 | | -useLatestMain: args.includes("--latest-main"), |
| 374 | + useLatestMain, |
| 375 | +}; |
| 376 | +} |
| 377 | + |
| 378 | +function consumePositiveIntFlag(args, index, flag) { |
| 379 | +const arg = args[index]; |
| 380 | +const inlinePrefix = `${flag}=`; |
| 381 | +if (arg.startsWith(inlinePrefix)) { |
| 382 | +return { |
| 383 | +nextIndex: index, |
| 384 | +value: parsePositiveInt(arg.slice(inlinePrefix.length), flag), |
| 385 | +}; |
| 386 | +} |
| 387 | +if (arg !== flag) { |
| 388 | +return null; |
| 389 | +} |
| 390 | +return { |
| 391 | +nextIndex: index + 1, |
| 392 | +value: parsePositiveInt(args[index + 1], flag), |
365 | 393 | }; |
366 | 394 | } |
367 | 395 | |
|