refactor(cli): convert debug subcommands to effectCmd (#25479)

This commit is contained in:
Kit Langton
2026-05-02 19:22:51 -04:00
committed by GitHub
parent 9d03d4419e
commit 4de44bbbef
6 changed files with 185 additions and 139 deletions
+34 -20
View File
@@ -1,7 +1,9 @@
import { AppRuntime } from "@/effect/app-runtime"
import { Effect } from "effect"
import { Snapshot } from "../../../snapshot"
import { bootstrap } from "../../bootstrap"
import { effectCmd } from "../../effect-cmd"
import { cmd } from "../cmd"
import { InstanceRef } from "@/effect/instance-ref"
import { InstanceStore } from "@/project/instance-store"
export const SnapshotCommand = cmd({
command: "snapshot",
@@ -10,17 +12,21 @@ export const SnapshotCommand = cmd({
async handler() {},
})
const TrackCommand = cmd({
const TrackCommand = effectCmd({
command: "track",
describe: "track current snapshot state",
async handler() {
await bootstrap(process.cwd(), async () => {
console.log(await AppRuntime.runPromise(Snapshot.Service.use((svc) => svc.track())))
})
},
handler: Effect.fn("Cli.debug.snapshot.track")(function* () {
const ctx = yield* InstanceRef
if (!ctx) return
const store = yield* InstanceStore.Service
return yield* Effect.gen(function* () {
const out = yield* Snapshot.Service.use((svc) => svc.track())
console.log(out)
}).pipe(Effect.ensuring(store.dispose(ctx)))
}),
})
const PatchCommand = cmd({
const PatchCommand = effectCmd({
command: "patch <hash>",
describe: "show patch for a snapshot hash",
builder: (yargs) =>
@@ -29,14 +35,18 @@ const PatchCommand = cmd({
description: "hash",
demandOption: true,
}),
async handler(args) {
await bootstrap(process.cwd(), async () => {
console.log(await AppRuntime.runPromise(Snapshot.Service.use((svc) => svc.patch(args.hash))))
})
},
handler: Effect.fn("Cli.debug.snapshot.patch")(function* (args) {
const ctx = yield* InstanceRef
if (!ctx) return
const store = yield* InstanceStore.Service
return yield* Effect.gen(function* () {
const out = yield* Snapshot.Service.use((svc) => svc.patch(args.hash))
console.log(out)
}).pipe(Effect.ensuring(store.dispose(ctx)))
}),
})
const DiffCommand = cmd({
const DiffCommand = effectCmd({
command: "diff <hash>",
describe: "show diff for a snapshot hash",
builder: (yargs) =>
@@ -45,9 +55,13 @@ const DiffCommand = cmd({
description: "hash",
demandOption: true,
}),
async handler(args) {
await bootstrap(process.cwd(), async () => {
console.log(await AppRuntime.runPromise(Snapshot.Service.use((svc) => svc.diff(args.hash))))
})
},
handler: Effect.fn("Cli.debug.snapshot.diff")(function* (args) {
const ctx = yield* InstanceRef
if (!ctx) return
const store = yield* InstanceStore.Service
return yield* Effect.gen(function* () {
const out = yield* Snapshot.Service.use((svc) => svc.diff(args.hash))
console.log(out)
}).pipe(Effect.ensuring(store.dispose(ctx)))
}),
})