Skip to content

Commit 31e329f

Browse files
committed
refactor(cli): migrate to typed .argument() for positional args
Move positional args from .command() string to .argument() calls, unifying the action callback to receive a single typed opts object.
1 parent 5477395 commit 31e329f

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

packages/admin/src/index.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,50 +55,54 @@ probe.addHelpSection("Examples:", [
5555
// ── probe termless ──
5656

5757
probe
58-
.command("termless [selectors...]")
58+
.command("termless")
59+
.argument("[selectors...]", "Backend selectors to probe")
5960
.description("Headless library probes via Termless backends")
6061
.option("--all", "Probe all backends")
6162
.option("-f, --force", "Re-run even if cached")
62-
.action(async (selectors: string[], opts: { all?: boolean; force?: boolean }) => {
63+
.action(async (opts: { selectors: string[]; all?: boolean; force?: boolean }) => {
6364
const { runTermlessProbes } = await import("./termless.ts")
64-
await runTermlessProbes(opts.all ? [] : selectors, opts)
65+
await runTermlessProbes(opts.all ? [] : opts.selectors, opts)
6566
})
6667

6768
// ── probe server ──
6869

6970
probe
70-
.command("server [daemon]")
71+
.command("server")
72+
.argument("[daemon]", "Daemon name to probe")
7173
.description("Probe running daemon servers")
7274
.option("--start", "Start daemon in this terminal")
7375
.option("-p, --port <port>", "Port for --start", parseInt)
7476
.option("--all", "Probe all running daemons")
75-
.action(async (daemon: string | undefined, opts: { start?: boolean; port?: number; all?: boolean }) => {
77+
.action(async (opts: { daemon?: string; start?: boolean; port?: number; all?: boolean }) => {
7678
const { handleServer } = await import("./server.ts")
77-
await handleServer(daemon, opts)
79+
await handleServer(opts.daemon, opts)
7880
})
7981

8082
// ── probe app ──
8183

8284
probe
83-
.command("app [terminal]")
85+
.command("app")
86+
.argument("[terminal]", "Terminal app to probe")
8487
.description("Launch and probe macOS terminal apps")
8588
.option("--all", "Probe all installed terminals")
8689
.option("-f, --force", "Re-run even if cached")
87-
.action(async (terminal: string | undefined, opts: { all?: boolean; force?: boolean }) => {
90+
.action(async (opts: { terminal?: string; all?: boolean; force?: boolean }) => {
8891
const { handleApp } = await import("./app.ts")
89-
await handleApp(terminal, opts)
92+
await handleApp(opts.terminal, opts)
9093
})
9194

9295
// ── probe mux ──
9396

9497
probe
95-
.command("mux [multiplexer]")
98+
.command("mux")
99+
.argument("[multiplexer]", "Multiplexer to probe (tmux, screen)")
96100
.description("Probe through terminal multiplexers (tmux, screen)")
97101
.option("--all", "Probe through all installed multiplexers")
98102
.option("-f, --force", "Re-run even if cached")
99-
.action(async (multiplexer: string | undefined, opts: { all?: boolean; force?: boolean }) => {
103+
.action(async (opts: { multiplexer?: string; all?: boolean; force?: boolean }) => {
100104
const { handleMux } = await import("./mux.ts")
101-
await handleMux(multiplexer, opts)
105+
await handleMux(opts.multiplexer, opts)
102106
})
103107

104108
// ── probe here ──

packages/terminfo.dev/src/index.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,14 @@ program.addHelpSection("Examples:", [
221221
// ── test ──
222222

223223
program
224-
.command("test [daemon]")
224+
.command("test")
225+
.argument("[daemon]", "Daemon name to test")
225226
.description("Test this terminal's feature support")
226227
.option("--json", "Output results as JSON")
227228
.option("--serve", "Start daemon for remote testing")
228229
.option("-p, --port <port>", "Port for --serve", uint)
229230
.option("--all", "Test all running daemons")
230-
.action(async (daemon: string | undefined, opts) => {
231+
.action(async (opts: { daemon?: string; json?: boolean; serve?: boolean; port?: number; all?: boolean }) => {
231232
// --serve: start daemon mode
232233
if (opts.serve) {
233234
const { startDaemon } = await import("./serve.ts")
@@ -236,25 +237,25 @@ program
236237
}
237238

238239
// --all or specific daemon: test remote daemons
239-
if (opts.all || daemon) {
240+
if (opts.all || opts.daemon) {
240241
const { listDaemons } = await import("./serve.ts")
241242
const daemons = listDaemons()
242243

243244
let targets = daemons
244-
if (daemon) {
245+
if (opts.daemon) {
245246
targets = daemons.filter(
246247
(d) =>
247-
d.terminal.toLowerCase() === daemon.toLowerCase() ||
248-
d.terminal.toLowerCase().includes(daemon.toLowerCase()),
248+
d.terminal.toLowerCase() === opts.daemon!.toLowerCase() ||
249+
d.terminal.toLowerCase().includes(opts.daemon!.toLowerCase()),
249250
)
250251
if (targets.length === 0) {
251-
console.error(`No daemon found matching "${daemon}".`)
252+
console.error(`No daemon found matching "${opts.daemon}".`)
252253
if (daemons.length > 0) {
253254
console.error(`Running: ${daemons.map((d) => d.terminal).join(", ")}`)
254255
} else {
255256
console.error(`No daemons running. Start one: terminfo test --serve`)
256257
}
257-
throw new Error(`No daemon found matching "${daemon}"`)
258+
throw new Error(`No daemon found matching "${opts.daemon}"`)
258259
}
259260
}
260261

0 commit comments

Comments
 (0)