Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
"@opentelemetry/core": "npm:@opentelemetry/core@^2.5.0",
"@opentelemetry/sdk-trace-base": "npm:@opentelemetry/sdk-trace-base@^2.5.0",
"@opentelemetry/semantic-conventions": "npm:@opentelemetry/semantic-conventions@^1.39.0",
"@optique/config": "jsr:@optique/config@^0.10.2",
"@optique/core": "jsr:@optique/core@^0.10.2",
"@optique/run": "jsr:@optique/run@^0.10.2",
"@optique/config": "jsr:@optique/config@^0.10.4",
"@optique/core": "jsr:@optique/core@^0.10.4",
"@optique/run": "jsr:@optique/run@^0.10.4",
"@std/assert": "jsr:@std/assert@^1.0.13",
"@std/async": "jsr:@std/async@^1.0.13",
"@std/encoding": "jsr:@std/encoding@^1.0.10",
Expand Down
29 changes: 16 additions & 13 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions packages/cli/src/inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { bindConfig } from "@optique/config";
import {
command,
constant,
group,
type InferValue,
merge,
message,
Expand Down Expand Up @@ -96,8 +97,6 @@ export const inboxCommand = command(
default: [],
},
),
}),
object({
actorName: bindConfig(
option("--actor-name", string({ metavar: "NAME" }), {
description: message`Customize the actor display name.`,
Expand Down Expand Up @@ -136,7 +135,7 @@ export const inboxCommand = command(
},
),
}),
createTunnelOption("inbox"),
group("Tunnel options", createTunnelOption("inbox")),
),
{
brief: message`Run an ephemeral ActivityPub inbox server.`,
Expand Down
50 changes: 28 additions & 22 deletions packages/cli/src/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { colorEnabled, colors, formatObject } from "./utils.ts";

const logger = getLogger(["fedify", "cli", "lookup"]);

export const authorizedFetchOption = object({
export const authorizedFetchOption = object("Authorized fetch options", {
authorizedFetch: bindConfig(
map(
flag("-a", "--authorized-fetch", {
Expand Down Expand Up @@ -87,7 +87,7 @@ export const authorizedFetchOption = object({
tunnelService: tunnelServiceOption,
});

const traverseOption = object({
const traverseOption = object("Traverse options", {
traverse: bindConfig(
flag("-t", "--traverse", {
description:
Expand Down Expand Up @@ -115,18 +115,41 @@ const traverseOption = object({
export const lookupCommand = command(
"lookup",
merge(
"Looking up options",
object({ command: constant("lookup") }),
traverseOption,
authorizedFetchOption,
userAgentOption,
object({
merge(
"Network options",
userAgentOption,
object({
timeout: optional(
bindConfig(
option(
"-T",
"--timeout",
float({ min: 0, metavar: "SECONDS" }),
{
description:
message`Set timeout for network requests in seconds.`,
},
),
{
context: configContext,
key: (config) => config.lookup?.timeout,
},
),
),
}),
),
object("Arguments", {
urls: multiple(
argument(string({ metavar: "URL_OR_HANDLE" }), {
description: message`One or more URLs or handles to look up.`,
}),
{ min: 1 },
),
}),
object("Output options", {
format: bindConfig(
optional(
or(
Expand Down Expand Up @@ -177,23 +200,6 @@ export const lookupCommand = command(
}),
{ description: message`Specify the output file path.` },
)),
timeout: optional(
bindConfig(
option(
"-T",
"--timeout",
float({ min: 0, metavar: "SECONDS" }),
{
description:
message`Set timeout for network requests in seconds.`,
},
),
{
context: configContext,
key: (config) => config.lookup?.timeout,
},
),
),
}),
),
{
Expand Down
35 changes: 26 additions & 9 deletions packages/cli/src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node --disable-warning=ExperimentalWarning
import { runWithConfig } from "@optique/config/run";
import { merge, message, or } from "@optique/core";
import { group, merge, message, or } from "@optique/core";
import { printError } from "@optique/run";
import { merge as deepMerge } from "es-toolkit";
import { readFileSync } from "node:fs";
Expand Down Expand Up @@ -56,14 +56,27 @@ function getUserConfigPath(): string {

const command = merge(
or(
initCommand,
webFingerCommand,
lookupCommand,
inboxCommand,
nodeInfoCommand,
tunnelCommand,
generateVocabCommand,
relayCommand,
group(
"Generating code",
or(
initCommand,
generateVocabCommand,
),
),
group(
"ActivityPub tools",
or(
webFingerCommand,
lookupCommand,
inboxCommand,
nodeInfoCommand,
relayCommand,
),
),
group(
"Network tools",
tunnelCommand,
),
),
globalOptions,
);
Expand Down Expand Up @@ -107,14 +120,18 @@ async function main() {
help: {
mode: "both",
onShow: () => process.exit(0),
group: "Meta commands",
},
version: {
mode: "both",
value: metadata.version,
group: "Meta commands",
},
completion: {
mode: "command",
name: "both",
helpVisibility: "plural",
group: "Meta commands",
},
onError: () => process.exit(1),
colors: process.stdout.isTTY &&
Expand Down
97 changes: 51 additions & 46 deletions packages/cli/src/nodeinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
command as Command,
constant,
flag,
group,
type InferValue,
merge,
message,
Expand All @@ -34,62 +35,66 @@ export const Jimp = createJimp({
plugins: defaultPlugins,
});

const nodeInfoOption = object({
raw: bindConfig(
flag("-r", "--raw", {
description: message`Show NodeInfo document in the raw JSON format`,
}),
{
context: configContext,
key: (config) => config.nodeinfo?.raw ?? false,
default: false,
},
),
bestEffort: bindConfig(
flag("-b", "--best-effort", {
description:
message`Parse the NodeInfo document with best effort. If the NodeInfo document is not well-formed, the option will try to parse it as much as possible.`,
}),
{
context: configContext,
key: (config) => config.nodeinfo?.bestEffort ?? false,
default: false,
},
),
noFavicon: bindConfig(
flag("--no-favicon", {
description: message`Disable fetching the favicon of the instance`,
}),
{
context: configContext,
key: (config) => config.nodeinfo?.showFavicon === false,
default: false,
},
),
metadata: bindConfig(
flag("-m", "--metadata", {
description:
message`Show the extra metadata of the NodeInfo, i.e., the metadata field of the document.`,
}),
{
context: configContext,
key: (config) => config.nodeinfo?.showMetadata ?? false,
default: false,
},
),
});
const nodeInfoOption = merge(
object("Display options", {
raw: bindConfig(
flag("-r", "--raw", {
description: message`Show NodeInfo document in the raw JSON format`,
}),
{
context: configContext,
key: (config) => config.nodeinfo?.raw ?? false,
default: false,
},
),
noFavicon: bindConfig(
flag("--no-favicon", {
description: message`Disable fetching the favicon of the instance`,
}),
{
context: configContext,
key: (config) => config.nodeinfo?.showFavicon === false,
default: false,
},
),
metadata: bindConfig(
flag("-m", "--metadata", {
description:
message`Show the extra metadata of the NodeInfo, i.e., the metadata field of the document.`,
}),
{
context: configContext,
key: (config) => config.nodeinfo?.showMetadata ?? false,
default: false,
},
),
}),
object("Parsing options", {
bestEffort: bindConfig(
flag("-b", "--best-effort", {
description:
message`Parse the NodeInfo document with best effort. If the NodeInfo document is not well-formed, the option will try to parse it as much as possible.`,
}),
{
context: configContext,
key: (config) => config.nodeinfo?.bestEffort ?? false,
default: false,
},
),
}),
);

export const nodeInfoCommand = Command(
"nodeinfo",
merge(
object({
object("Arguments", {
command: constant("nodeinfo"),
host: argument(string({ metavar: "HOST" }), {
description: message`Bare hostname or a full URL of the instance`,
}),
}),
nodeInfoOption,
userAgentOption,
group("Network options", userAgentOption),
),
{
brief:
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { bindConfig } from "@optique/config";
import {
command,
constant,
group,
type InferValue,
integer,
merge,
Expand Down Expand Up @@ -120,7 +121,7 @@ export const relayCommand = command(
},
),
}),
createTunnelOption("relay"),
group("Tunnel options", createTunnelOption("relay")),
),
{
brief: message`Run an ephemeral ActivityPub relay server.`,
Expand Down
Loading
Loading