Skip to content

Commit 6e28e6e

Browse files
authored
Merge pull request #728 from dahlia/bugfix/cli
Fix CLI config fallbacks for Optique 1.0
2 parents d2a1ce2 + ea162f5 commit 6e28e6e

8 files changed

Lines changed: 141 additions & 70 deletions

File tree

deno.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@
4949
"@opentelemetry/core": "npm:@opentelemetry/core@^2.5.0",
5050
"@opentelemetry/sdk-trace-base": "npm:@opentelemetry/sdk-trace-base@^2.5.0",
5151
"@opentelemetry/semantic-conventions": "npm:@opentelemetry/semantic-conventions@^1.39.0",
52-
"@optique/config": "jsr:@optique/config@^1.0.0",
53-
"@optique/core": "jsr:@optique/core@^1.0.0",
54-
"@optique/run": "jsr:@optique/run@^1.0.0",
52+
"@optique/config": "jsr:@optique/config@^1.0.2",
53+
"@optique/core": "jsr:@optique/core@^1.0.2",
54+
"@optique/run": "jsr:@optique/run@^1.0.2",
55+
"@standard-schema/spec": "jsr:@standard-schema/spec@^1.1.0",
5556
"@std/assert": "jsr:@std/assert@^1.0.13",
5657
"@std/async": "jsr:@std/async@^1.0.13",
5758
"@std/encoding": "jsr:@std/encoding@^1.0.10",

deno.lock

Lines changed: 18 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"@optique/config": "catalog:",
8585
"@optique/core": "catalog:",
8686
"@optique/run": "catalog:",
87+
"@standard-schema/spec": "catalog:",
8788
"@hongminhee/localtunnel": "^0.3.0",
8889
"@inquirer/prompts": "^7.8.4",
8990
"@jimp/core": "^1.6.0",

packages/cli/src/lookup.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,21 @@ const lookupModeOption = withDefault(
163163
key: (config) => config.lookup?.recurse,
164164
},
165165
),
166-
recurseDepth: withDefault(
167-
bindConfig(
168-
option(
169-
"--recurse-depth",
170-
integer({ min: 1, metavar: "DEPTH" }),
171-
{
172-
description: message`Maximum recursion depth for ${
173-
optionNames(["--recurse"])
174-
}.`,
175-
},
176-
),
166+
recurseDepth: bindConfig(
167+
option(
168+
"--recurse-depth",
169+
integer({ min: 1, metavar: "DEPTH" }),
177170
{
178-
context: configContext,
179-
key: (config) => config.lookup?.recurseDepth,
171+
description: message`Maximum recursion depth for ${
172+
optionNames(["--recurse"])
173+
}.`,
180174
},
181175
),
182-
20,
176+
{
177+
context: configContext,
178+
key: (config) => config.lookup?.recurseDepth,
179+
default: 20,
180+
},
183181
),
184182
suppressErrors: suppressErrorsOption,
185183
}),

packages/cli/src/options.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
message,
1111
object,
1212
option,
13+
optional,
1314
type OptionName,
1415
or,
1516
string,
@@ -40,7 +41,7 @@ export function createTunnelServiceOption(
4041
const [firstOptionName, ...restOptionNames] = optionNames;
4142
// Note that we don't provide a default value here, since the tunneling
4243
// implementation will randomly select a service if none is specified.
43-
return withDefault(
44+
return optional(
4445
bindConfig(
4546
option(
4647
firstOptionName,
@@ -57,7 +58,6 @@ By default, any of the supported tunneling services will be used
5758
key: (config) => config.tunnelService,
5859
},
5960
),
60-
undefined,
6161
);
6262
}
6363

@@ -76,19 +76,21 @@ type TunnelConfigSection = "inbox" | "relay";
7676
export function createTunnelOption<S extends TunnelConfigSection>(section: S) {
7777
return object({
7878
tunnel: bindConfig(
79-
withDefault(
80-
map(
81-
flag("-T", "--no-tunnel", {
82-
description:
83-
message`Do not tunnel the server to the public Internet.`,
84-
}),
85-
() => false as const,
86-
),
87-
true,
79+
map(
80+
flag("-T", "--no-tunnel", {
81+
description:
82+
message`Do not tunnel the server to the public Internet.`,
83+
}),
84+
() => false as const,
8885
),
8986
{
9087
context: configContext,
91-
key: (config: Config) => !(config[section]?.noTunnel ?? false),
88+
key: (config: Config) => {
89+
const sectionConfig = config[section];
90+
return sectionConfig?.noTunnel == null
91+
? undefined
92+
: !sectionConfig.noTunnel;
93+
},
9294
default: true,
9395
},
9496
),

packages/cli/src/tunnel.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Tunnel, TunnelOptions } from "@hongminhee/localtunnel";
22
import { runSync } from "@optique/run";
33
import { deepEqual, rejects } from "node:assert/strict";
44
import test from "node:test";
5+
import { runCli } from "./runner.ts";
56
import type { Ora } from "ora";
67
import { runTunnel, tunnelCommand } from "./tunnel.ts";
78

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

25+
test("tunnel runner accepts omitted tunnel service", async () => {
26+
const result = await runCli(["tunnel", "3000", "--ignore-config"]);
27+
28+
deepEqual(result.command, "tunnel");
29+
deepEqual(result.port, 3000);
30+
deepEqual((result as { service?: unknown }).service, undefined);
31+
});
32+
33+
test("inbox runner accepts tunnel options without a tunnel service", async () => {
34+
const withoutTunnel = await runCli([
35+
"inbox",
36+
"--no-tunnel",
37+
"--ignore-config",
38+
]);
39+
const withOtherOption = await runCli([
40+
"inbox",
41+
"--actor-name",
42+
"Test Inbox",
43+
"--ignore-config",
44+
]);
45+
46+
deepEqual(withoutTunnel.command, "inbox");
47+
deepEqual((withoutTunnel as { tunnel?: unknown }).tunnel, false);
48+
deepEqual(
49+
(withoutTunnel as { tunnelService?: unknown }).tunnelService,
50+
undefined,
51+
);
52+
deepEqual(withOtherOption.command, "inbox");
53+
deepEqual((withOtherOption as { tunnel?: unknown }).tunnel, true);
54+
deepEqual(
55+
(withOtherOption as { actorName?: unknown }).actorName,
56+
"Test Inbox",
57+
);
58+
deepEqual(
59+
(withOtherOption as { tunnelService?: unknown }).tunnelService,
60+
undefined,
61+
);
62+
});
63+
64+
test("relay runner accepts tunnel options without a tunnel service", async () => {
65+
const result = await runCli([
66+
"relay",
67+
"--no-tunnel",
68+
"--ignore-config",
69+
]);
70+
71+
deepEqual(result.command, "relay");
72+
deepEqual((result as { tunnel?: unknown }).tunnel, false);
73+
deepEqual((result as { tunnelService?: unknown }).tunnelService, undefined);
74+
});
75+
2476
test("tunnel successfully creates and manages tunnel", async () => {
2577
const mockCommand = {
2678
command: "tunnel" as const,

pnpm-lock.yaml

Lines changed: 36 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ catalog:
5757
"@opentelemetry/sdk-node": ^0.211.0
5858
"@opentelemetry/sdk-trace-base": ^2.5.0
5959
"@opentelemetry/semantic-conventions": ^1.39.0
60-
"@optique/config": ^1.0.0
61-
"@optique/core": ^1.0.0
62-
"@optique/run": ^1.0.0
60+
"@optique/config": ^1.0.2
61+
"@optique/core": ^1.0.2
62+
"@optique/run": ^1.0.2
63+
"@standard-schema/spec": ^1.1.0
6364
"@std/assert": "jsr:^1.0.13"
6465
"@std/async": "jsr:^1.0.13"
6566
"@std/path": "jsr:^1.0.6"

0 commit comments

Comments
 (0)