import path from "path"; import { commitVerifiedContractInfo, RegistryCommitSelection, } from "./lib/registryCommit"; const parseArgs = (argv: string[]): Record => { const args: Record = {}; for (let index = 0; index < argv.length; index += 1) { const item = argv[index]; if (!item.startsWith("--")) continue; const key = item.slice(2); const value = argv[index + 1]; if (!value || value.startsWith("--")) throw new Error(`--${key} requires a value`); (args[key] ||= []).push(value); index += 1; } return args; }; const single = (args: Record, key: string, required = false): string | undefined => { const values = args[key] || []; if (values.length > 1) throw new Error(`--${key} may be provided only once`); const value = values[0]?.trim(); if (required && !value) throw new Error(`--${key} is required`); return value; }; const selection = (value: string): RegistryCommitSelection => { const index = value.indexOf("="); if (index <= 0 || index === value.length - 1) { throw new Error("--selection must use ="); } return { network: value.slice(0, index), executionId: value.slice(index + 1) }; }; const main = (): void => { const args = parseArgs(process.argv.slice(2)); const report = commitVerifiedContractInfo({ root: path.resolve(single(args, "root") || process.cwd()), taskId: single(args, "task", true) as string, commitId: single(args, "commitId", true) as string, selections: (args.selection || []).map(selection), }); console.log(JSON.stringify({ status: report.status, commitId: report.commitId, selections: report.selections, afterHash: report.afterHash, })); }; try { main(); } catch (error) { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; }