Skip to content

Commit 0c816eb

Browse files
authored
refactor(cli): convert plugin command to effectCmd (#25473)
1 parent e318e17 commit 0c816eb

2 files changed

Lines changed: 21 additions & 22 deletions

File tree

packages/opencode/src/cli/cmd/plug.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { intro, log, outro, spinner } from "@clack/prompts"
2-
import type { Argv } from "yargs"
2+
import { Effect } from "effect"
33

44
import { ConfigPaths } from "@/config/paths"
55
import { Global } from "@opencode-ai/core/global"
66
import { installPlugin, patchPluginConfig, readPluginManifest } from "../../plugin/install"
77
import { resolvePluginTarget } from "../../plugin/shared"
8-
import { Instance } from "../../project/instance"
98
import { errorMessage } from "../../util/error"
109
import { Filesystem } from "@/util/filesystem"
1110
import { Process } from "@/util/process"
1211
import { UI } from "../ui"
13-
import { cmd } from "./cmd"
12+
import { effectCmd } from "../effect-cmd"
13+
import { InstanceRef } from "@/effect/instance-ref"
1414

1515
type Spin = {
1616
start: (msg: string) => void
@@ -175,12 +175,12 @@ export function createPlugTask(input: PlugInput, dep: PlugDeps = defaultPlugDeps
175175
}
176176
}
177177

178-
export const PluginCommand = cmd({
178+
export const PluginCommand = effectCmd({
179179
command: "plugin <module>",
180180
aliases: ["plug"],
181181
describe: "install plugin and update config",
182-
builder: (yargs: Argv) => {
183-
return yargs
182+
builder: (yargs) =>
183+
yargs
184184
.positional("module", {
185185
type: "string",
186186
describe: "npm module name",
@@ -196,9 +196,8 @@ export const PluginCommand = cmd({
196196
type: "boolean",
197197
default: false,
198198
describe: "replace existing plugin version",
199-
})
200-
},
201-
handler: async (args) => {
199+
}),
200+
handler: Effect.fn("Cli.plug")(function* (args) {
202201
const mod = String(args.module ?? "").trim()
203202
if (!mod) {
204203
UI.error("module is required")
@@ -214,20 +213,18 @@ export const PluginCommand = cmd({
214213
global: Boolean(args.global),
215214
force: Boolean(args.force),
216215
})
217-
let ok = true
218-
219-
await Instance.provide({
220-
directory: process.cwd(),
221-
fn: async () => {
222-
ok = await run({
223-
vcs: Instance.project.vcs,
224-
worktree: Instance.worktree,
225-
directory: Instance.directory,
226-
})
227-
},
228-
})
216+
217+
const ctx = yield* InstanceRef
218+
if (!ctx) return
219+
const ok = yield* Effect.promise(() =>
220+
run({
221+
vcs: ctx.project.vcs,
222+
worktree: ctx.worktree,
223+
directory: ctx.directory,
224+
}),
225+
)
229226

230227
outro("Done")
231228
if (!ok) process.exitCode = 1
232-
},
229+
}),
233230
})

packages/opencode/src/cli/effect-cmd.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const fail = (message: string, exitCode = 1) => Effect.fail(new CliError(
3131
*/
3232
export const effectCmd = <Args, A>(opts: {
3333
command: string | readonly string[]
34+
aliases?: string | readonly string[]
3435
describe: string | false
3536
builder?: (yargs: Argv) => Argv<Args>
3637
/** Defaults to process.cwd(). Override for commands that take a directory positional. */
@@ -39,6 +40,7 @@ export const effectCmd = <Args, A>(opts: {
3940
}) =>
4041
cmd<{}, Args>({
4142
command: opts.command,
43+
aliases: opts.aliases,
4244
describe: opts.describe,
4345
builder: opts.builder as never,
4446
async handler(rawArgs) {

0 commit comments

Comments
 (0)