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
7 changes: 4 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
"@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@^1.0.0",
"@optique/core": "jsr:@optique/core@^1.0.0",
"@optique/run": "jsr:@optique/run@^1.0.0",
"@optique/config": "jsr:@optique/config@^1.0.2",
"@optique/core": "jsr:@optique/core@^1.0.2",
"@optique/run": "jsr:@optique/run@^1.0.2",
"@standard-schema/spec": "jsr:@standard-schema/spec@^1.1.0",
"@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
31 changes: 18 additions & 13 deletions deno.lock

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

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@optique/config": "catalog:",
"@optique/core": "catalog:",
"@optique/run": "catalog:",
"@standard-schema/spec": "catalog:",
"@hongminhee/localtunnel": "^0.3.0",
"@inquirer/prompts": "^7.8.4",
"@jimp/core": "^1.6.0",
Expand Down
26 changes: 12 additions & 14 deletions packages/cli/src/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,21 @@ const lookupModeOption = withDefault(
key: (config) => config.lookup?.recurse,
},
),
recurseDepth: withDefault(
bindConfig(
option(
"--recurse-depth",
integer({ min: 1, metavar: "DEPTH" }),
{
description: message`Maximum recursion depth for ${
optionNames(["--recurse"])
}.`,
},
),
recurseDepth: bindConfig(
option(
"--recurse-depth",
integer({ min: 1, metavar: "DEPTH" }),
{
context: configContext,
key: (config) => config.lookup?.recurseDepth,
description: message`Maximum recursion depth for ${
optionNames(["--recurse"])
}.`,
},
),
20,
{
context: configContext,
key: (config) => config.lookup?.recurseDepth,
default: 20,
},
),
suppressErrors: suppressErrorsOption,
}),
Expand Down
26 changes: 14 additions & 12 deletions packages/cli/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
message,
object,
option,
optional,
type OptionName,
or,
string,
Expand Down Expand Up @@ -40,7 +41,7 @@ export function createTunnelServiceOption(
const [firstOptionName, ...restOptionNames] = optionNames;
// Note that we don't provide a default value here, since the tunneling
// implementation will randomly select a service if none is specified.
return withDefault(
return optional(
bindConfig(
option(
firstOptionName,
Expand All @@ -57,7 +58,6 @@ By default, any of the supported tunneling services will be used
key: (config) => config.tunnelService,
},
),
undefined,
);
}

Expand All @@ -76,19 +76,21 @@ type TunnelConfigSection = "inbox" | "relay";
export function createTunnelOption<S extends TunnelConfigSection>(section: S) {
return object({
tunnel: bindConfig(
withDefault(
map(
flag("-T", "--no-tunnel", {
description:
message`Do not tunnel the server to the public Internet.`,
}),
() => false as const,
),
true,
map(
flag("-T", "--no-tunnel", {
description:
message`Do not tunnel the server to the public Internet.`,
}),
() => false as const,
),
{
context: configContext,
key: (config: Config) => !(config[section]?.noTunnel ?? false),
key: (config: Config) => {
const sectionConfig = config[section];
return sectionConfig?.noTunnel == null
? undefined
: !sectionConfig.noTunnel;
},
default: true,
},
),
Expand Down
52 changes: 52 additions & 0 deletions packages/cli/src/tunnel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Tunnel, TunnelOptions } from "@hongminhee/localtunnel";
import { runSync } from "@optique/run";
import { deepEqual, rejects } from "node:assert/strict";
import test from "node:test";
import { runCli } from "./runner.ts";
import type { Ora } from "ora";
import { runTunnel, tunnelCommand } from "./tunnel.ts";

Expand All @@ -21,6 +22,57 @@ test("tunnel command structure", () => {
deepEqual(testCommandWithoutOptions.service, undefined);
});

test("tunnel runner accepts omitted tunnel service", async () => {
const result = await runCli(["tunnel", "3000", "--ignore-config"]);

deepEqual(result.command, "tunnel");
deepEqual(result.port, 3000);
deepEqual((result as { service?: unknown }).service, undefined);
});

test("inbox runner accepts tunnel options without a tunnel service", async () => {
const withoutTunnel = await runCli([
"inbox",
"--no-tunnel",
"--ignore-config",
]);
const withOtherOption = await runCli([
"inbox",
"--actor-name",
"Test Inbox",
"--ignore-config",
]);

deepEqual(withoutTunnel.command, "inbox");
deepEqual((withoutTunnel as { tunnel?: unknown }).tunnel, false);
deepEqual(
(withoutTunnel as { tunnelService?: unknown }).tunnelService,
undefined,
);
deepEqual(withOtherOption.command, "inbox");
deepEqual((withOtherOption as { tunnel?: unknown }).tunnel, true);
deepEqual(
(withOtherOption as { actorName?: unknown }).actorName,
"Test Inbox",
);
deepEqual(
(withOtherOption as { tunnelService?: unknown }).tunnelService,
undefined,
);
});

test("relay runner accepts tunnel options without a tunnel service", async () => {
const result = await runCli([
"relay",
"--no-tunnel",
"--ignore-config",
]);

deepEqual(result.command, "relay");
deepEqual((result as { tunnel?: unknown }).tunnel, false);
deepEqual((result as { tunnelService?: unknown }).tunnelService, undefined);
});

test("tunnel successfully creates and manages tunnel", async () => {
const mockCommand = {
command: "tunnel" as const,
Expand Down
61 changes: 36 additions & 25 deletions pnpm-lock.yaml

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

7 changes: 4 additions & 3 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ catalog:
"@opentelemetry/sdk-node": ^0.211.0
"@opentelemetry/sdk-trace-base": ^2.5.0
"@opentelemetry/semantic-conventions": ^1.39.0
"@optique/config": ^1.0.0
"@optique/core": ^1.0.0
"@optique/run": ^1.0.0
"@optique/config": ^1.0.2
"@optique/core": ^1.0.2
"@optique/run": ^1.0.2
"@standard-schema/spec": ^1.1.0
"@std/assert": "jsr:^1.0.13"
"@std/async": "jsr:^1.0.13"
"@std/path": "jsr:^1.0.6"
Expand Down
Loading