mirror of
https://github.com/jakejarvis/rdapper.git
synced 2026-10-26 08:26:22 -04:00
The CLI looked up only the last argument (an option like --rdap-only was taken as the domain), always exited 0, and started every stdin line's lookup at once, so results could print out of order and many lines hit registries together. Look up each argument, or each non-blank stdin line, one at a time in order; exit 1 when any lookup fails and 2 on an unknown option. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.0 KiB
JavaScript
Executable File
39 lines
1.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
// Quick informal command-line interface for rdapper
|
|
// Usage:
|
|
// npx rdapper example.com [example.org ...]
|
|
// echo "example.com" | npx rdapper
|
|
// Exits with 1 when any lookup fails.
|
|
|
|
import { createInterface } from "node:readline";
|
|
import { lookup } from "../dist/index.mjs";
|
|
|
|
/** Domains from the arguments, or else one per non-blank line of stdin. */
|
|
async function* domains() {
|
|
const args = process.argv.slice(2);
|
|
if (args.length) {
|
|
yield* args;
|
|
return;
|
|
}
|
|
for await (const line of createInterface({ input: process.stdin })) {
|
|
if (line.trim()) yield line;
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
// One at a time, so output follows input order and registries aren't flooded
|
|
for await (const domain of domains()) {
|
|
if (domain.startsWith("-")) {
|
|
console.error(`Unknown option: ${domain}`);
|
|
process.exitCode = 2;
|
|
return;
|
|
}
|
|
const result = await lookup(domain);
|
|
if (!result.ok) process.exitCode = 1;
|
|
console.log(JSON.stringify(result, null, 2));
|
|
}
|
|
}
|
|
|
|
void main();
|