import type { ConsumerCiArtifactsCliOptions } from './collect-consumer-ci-artifacts-contract'; import { DEFAULT_LIMIT, DEFAULT_OUT_FILE, } from './collect-consumer-ci-artifacts-contract'; export const parseConsumerCiArtifactsArgs = ( args: ReadonlyArray ): ConsumerCiArtifactsCliOptions => { const options: ConsumerCiArtifactsCliOptions = { repo: '', limit: DEFAULT_LIMIT, outFile: DEFAULT_OUT_FILE, }; for (let index = 0; index < args.length; index += 1) { const arg = args[index]; if (arg === '--repo') { const value = args[index + 1]; if (!value) { throw new Error('Missing value for --repo'); } options.repo = value; index += 1; continue; } if (arg === '--limit') { const value = args[index + 1]; if (!value) { throw new Error('Missing value for --limit'); } const parsed = Number.parseInt(value, 10); if (!Number.isFinite(parsed) || parsed <= 0) { throw new Error(`Invalid --limit value: ${value}`); } options.limit = parsed; index += 1; continue; } if (arg === '--out') { const value = args[index + 1]; if (!value) { throw new Error('Missing value for --out'); } options.outFile = value; index += 1; continue; } throw new Error(`Unknown argument: ${arg}`); } if (!options.repo) { throw new Error('Missing required argument --repo '); } return options; };