Loading cli/lookup.ts 0 → 100644 +32 −0 Original line number Diff line number Diff line import { Command } from "@cliffy/command"; import { lookupObject } from "@fedify/fedify"; import { highlight } from "cli-highlight"; export const command = new Command() .arguments("<url:string>") .description( "Lookup an Activity Streams object by URL or the actor handle. " + "The argument can be either a URL or an actor handle " + "(e.g., @username@domain).", ) .option("-c, --compact", "Compact the fetched JSON-LD document.", { conflicts: ["expand"], }) .option("-e, --expand", "Expand the fetched JSON-LD document.", { conflicts: ["compact"], }) .action(async (options, url: string) => { const object = await lookupObject(url); if (options.compact) { printJson(await object?.toJsonLd()); } else if (options.expand) { printJson(await object?.toJsonLd({ expand: true })); } else { console.log(object); } }); function printJson(json: unknown): void { const formatted = JSON.stringify(json, null, 2); console.log(highlight(formatted, { language: "json" })); } cli/mod.ts 0 → 100644 +35 −0 Original line number Diff line number Diff line import { Command, HelpCommand } from "@cliffy/command"; import { configure, getConsoleSink } from "@logtape/logtape"; import metadata from "../deno.json" with { type: "json" }; import { command as lookup } from "./lookup.ts"; const command = new Command() .name("fedify") .version(metadata.version) .globalOption("-d, --debug", "Enable debug mode.", { async action() { await configure({ sinks: { console: getConsoleSink() }, filters: {}, loggers: [ { category: "fedify", level: "debug", sinks: ["console"], }, { category: ["logtape", "meta"], level: "warning", sinks: ["console"], }, ], }); }, }) .default("help") .command("lookup", lookup) .command("help", new HelpCommand().global()); if (import.meta.main) { await command.parse(Deno.args); } deno.json +3 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ }, "imports": { "@cfworker/json-schema": "npm:@cfworker/json-schema@^1.12.8", "@cliffy/command": "https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts", "@david/which-runtime": "jsr:@david/which-runtime@^0.2.0", "@deno/dnt": "jsr:@deno/dnt@^0.41.1", "@fedify/fedify": "./mod.ts", Loading Loading @@ -46,6 +47,7 @@ "@std/text": "jsr:@std/text@^0.220.1", "@std/url": "jsr:@std/url@^0.220.1", "@std/yaml": "jsr:@std/yaml@^0.220.1", "cli-highlight": "npm:cli-highlight@^2.1.11", "fast-check": "npm:fast-check@^3.17.0", "jsonld": "npm:jsonld@^8.3.2", "mock_fetch": "https://deno.land/x/mock_fetch@0.3.0/mod.ts", Loading @@ -66,6 +68,7 @@ "cache": "deno task codegen && deno cache mod.ts", "check": "deno task codegen && deno fmt --check && deno lint && deno check */*.ts", "codegen": "deno run --allow-read --allow-write --check codegen/main.ts vocab/ ../runtime/ > vocab/vocab.ts && deno fmt vocab/vocab.ts && deno cache vocab/vocab.ts && deno check vocab/vocab.ts", "cli": "deno task codegen && deno run --allow-read --allow-net --allow-env cli/mod.ts", "test-without-codegen": "deno test --check --doc --allow-read --allow-write --unstable-kv --trace-leaks", "test": "deno task codegen && deno task test-without-codegen", "coverage": "rm -rf coverage/ && deno task test --coverage && deno coverage --html coverage", Loading Loading
cli/lookup.ts 0 → 100644 +32 −0 Original line number Diff line number Diff line import { Command } from "@cliffy/command"; import { lookupObject } from "@fedify/fedify"; import { highlight } from "cli-highlight"; export const command = new Command() .arguments("<url:string>") .description( "Lookup an Activity Streams object by URL or the actor handle. " + "The argument can be either a URL or an actor handle " + "(e.g., @username@domain).", ) .option("-c, --compact", "Compact the fetched JSON-LD document.", { conflicts: ["expand"], }) .option("-e, --expand", "Expand the fetched JSON-LD document.", { conflicts: ["compact"], }) .action(async (options, url: string) => { const object = await lookupObject(url); if (options.compact) { printJson(await object?.toJsonLd()); } else if (options.expand) { printJson(await object?.toJsonLd({ expand: true })); } else { console.log(object); } }); function printJson(json: unknown): void { const formatted = JSON.stringify(json, null, 2); console.log(highlight(formatted, { language: "json" })); }
cli/mod.ts 0 → 100644 +35 −0 Original line number Diff line number Diff line import { Command, HelpCommand } from "@cliffy/command"; import { configure, getConsoleSink } from "@logtape/logtape"; import metadata from "../deno.json" with { type: "json" }; import { command as lookup } from "./lookup.ts"; const command = new Command() .name("fedify") .version(metadata.version) .globalOption("-d, --debug", "Enable debug mode.", { async action() { await configure({ sinks: { console: getConsoleSink() }, filters: {}, loggers: [ { category: "fedify", level: "debug", sinks: ["console"], }, { category: ["logtape", "meta"], level: "warning", sinks: ["console"], }, ], }); }, }) .default("help") .command("lookup", lookup) .command("help", new HelpCommand().global()); if (import.meta.main) { await command.parse(Deno.args); }
deno.json +3 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ }, "imports": { "@cfworker/json-schema": "npm:@cfworker/json-schema@^1.12.8", "@cliffy/command": "https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts", "@david/which-runtime": "jsr:@david/which-runtime@^0.2.0", "@deno/dnt": "jsr:@deno/dnt@^0.41.1", "@fedify/fedify": "./mod.ts", Loading Loading @@ -46,6 +47,7 @@ "@std/text": "jsr:@std/text@^0.220.1", "@std/url": "jsr:@std/url@^0.220.1", "@std/yaml": "jsr:@std/yaml@^0.220.1", "cli-highlight": "npm:cli-highlight@^2.1.11", "fast-check": "npm:fast-check@^3.17.0", "jsonld": "npm:jsonld@^8.3.2", "mock_fetch": "https://deno.land/x/mock_fetch@0.3.0/mod.ts", Loading @@ -66,6 +68,7 @@ "cache": "deno task codegen && deno cache mod.ts", "check": "deno task codegen && deno fmt --check && deno lint && deno check */*.ts", "codegen": "deno run --allow-read --allow-write --check codegen/main.ts vocab/ ../runtime/ > vocab/vocab.ts && deno fmt vocab/vocab.ts && deno cache vocab/vocab.ts && deno check vocab/vocab.ts", "cli": "deno task codegen && deno run --allow-read --allow-net --allow-env cli/mod.ts", "test-without-codegen": "deno test --check --doc --allow-read --allow-write --unstable-kv --trace-leaks", "test": "deno task codegen && deno task test-without-codegen", "coverage": "rm -rf coverage/ && deno task test --coverage && deno coverage --html coverage", Loading