Something went wrong. Try again.
Something went wrong. Try again.
1.8 kB · 42 lines
JavaScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243// Shared CLI helpers: colors, validation reporting, dry-run printing, and// pulling auth out of flags/env.
export const C = { dim: (s) => `\x1b[2m${s}\x1b[0m`, bold: (s) => `\x1b[1m${s}\x1b[0m`, cyan: (s) => `\x1b[36m${s}\x1b[0m`, green: (s) => `\x1b[32m${s}\x1b[0m`, yellow: (s) => `\x1b[33m${s}\x1b[0m`, red: (s) => `\x1b[31m${s}\x1b[0m`,};
// Print errors/warnings for one record. Returns true if it has blocking errors.export function report(label, { errors, warnings }) { if (errors.length) { console.error(`\n${C.red("✗")} ${C.bold(label)} — ${errors.length} error(s):`); for (const e of errors) console.error(` ${C.red("•")} ${e}`); } if (warnings.length) { console.error(`\n${C.yellow("!")} ${C.bold(label)} — ${warnings.length} warning(s):`); for (const w of warnings) console.error(` ${C.yellow("•")} ${w}`); } if (!errors.length && !warnings.length) console.error(`${C.green("✓")} ${label} — looks good`); return errors.length > 0;}
// Show exactly what a write would do, without doing it.export function printDryRun({ pds, did, collection, record }) { console.log(`\n${C.dim("# dry-run — no record written")}`); console.log(`${C.bold("POST")} ${pds || "<your-pds>"}/xrpc/com.atproto.repo.createRecord`); console.log(C.dim(`# as repo: ${did || "<your-did>"} collection: ${collection}`)); console.log(JSON.stringify({ repo: did || "<your-did>", collection, record }, null, 2));}
// identifier/password from flags first, then env. (PDS_IDENTIFIER / PDS_APP_PASSWORD)export function authFromArgs(a) { return { identifier: a.identifier || process.env.PDS_IDENTIFIER || process.env.PDS_HANDLE, password: a.password || process.env.PDS_APP_PASSWORD, pds: a.pds || process.env.PDS_URL, };}