46 lines
1006 B
TypeScript
Executable File
46 lines
1006 B
TypeScript
Executable File
#!/usr/bin/env -S deno run -A
|
|
|
|
import { parseArgs } from "jsr:@std/cli/parse-args";
|
|
import {
|
|
args,
|
|
exit,
|
|
fetchFileWithCache,
|
|
readFileToString,
|
|
} from "https://global.hatter.ink/script/get/@63/deno-commons-mod.ts";
|
|
|
|
const flags = parseArgs(args(), {
|
|
boolean: ["help"],
|
|
string: ["id"],
|
|
});
|
|
|
|
function printHelp() {
|
|
console.log("get-rfc.ts --id <RFC ID>");
|
|
}
|
|
|
|
if (flags.help) {
|
|
printHelp();
|
|
exit(0);
|
|
}
|
|
|
|
if (flags.id) {
|
|
const rfcId = parseInt(flags.id, 10);
|
|
if (isNaN(rfcId)) {
|
|
console.error("Invalid RFC id");
|
|
exit(1);
|
|
}
|
|
await getAndPrintRfc(rfcId);
|
|
} else {
|
|
printHelp();
|
|
exit(1);
|
|
}
|
|
|
|
async function getAndPrintRfc(rfcId: number): Promise<void> {
|
|
const url = `https://play.hatter.me/ietf/rfc${rfcId}.txt`;
|
|
const fileMeta = await fetchFileWithCache(url, {
|
|
base32Filename: true,
|
|
hierarchicalCacheDir: true,
|
|
});
|
|
const content = await readFileToString(fileMeta.cache_full_path);
|
|
console.log(content);
|
|
}
|