diff options
| author | Kit Langton <[email protected]> | 2026-05-02 17:55:13 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-05-02 17:55:13 -0400 |
| commit | 0c816eb4b1de0c5999d8c5349a34deb52a250d7d (patch) | |
| tree | 2989fd773b9a460bde985aa20cad81d005c3639e /packages | |
| parent | e318e173d8cc9c9bc92c2171d0d858edf525db48 (diff) | |
| download | opencode-0c816eb4b1de0c5999d8c5349a34deb52a250d7d.tar.gz opencode-0c816eb4b1de0c5999d8c5349a34deb52a250d7d.zip | |
refactor(cli): convert plugin command to effectCmd (#25473)
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/src/cli/cmd/plug.ts | 41 | ||||
| -rw-r--r-- | packages/opencode/src/cli/effect-cmd.ts | 2 |
2 files changed, 21 insertions, 22 deletions
diff --git a/packages/opencode/src/cli/cmd/plug.ts b/packages/opencode/src/cli/cmd/plug.ts index 1ac0b071d..1529e9b71 100644 --- a/packages/opencode/src/cli/cmd/plug.ts +++ b/packages/opencode/src/cli/cmd/plug.ts @@ -1,16 +1,16 @@ import { intro, log, outro, spinner } from "@clack/prompts" -import type { Argv } from "yargs" +import { Effect } from "effect" import { ConfigPaths } from "@/config/paths" import { Global } from "@opencode-ai/core/global" import { installPlugin, patchPluginConfig, readPluginManifest } from "../../plugin/install" import { resolvePluginTarget } from "../../plugin/shared" -import { Instance } from "../../project/instance" import { errorMessage } from "../../util/error" import { Filesystem } from "@/util/filesystem" import { Process } from "@/util/process" import { UI } from "../ui" -import { cmd } from "./cmd" +import { effectCmd } from "../effect-cmd" +import { InstanceRef } from "@/effect/instance-ref" type Spin = { start: (msg: string) => void @@ -175,12 +175,12 @@ export function createPlugTask(input: PlugInput, dep: PlugDeps = defaultPlugDeps } } -export const PluginCommand = cmd({ +export const PluginCommand = effectCmd({ command: "plugin <module>", aliases: ["plug"], describe: "install plugin and update config", - builder: (yargs: Argv) => { - return yargs + builder: (yargs) => + yargs .positional("module", { type: "string", describe: "npm module name", @@ -196,9 +196,8 @@ export const PluginCommand = cmd({ type: "boolean", default: false, describe: "replace existing plugin version", - }) - }, - handler: async (args) => { + }), + handler: Effect.fn("Cli.plug")(function* (args) { const mod = String(args.module ?? "").trim() if (!mod) { UI.error("module is required") @@ -214,20 +213,18 @@ export const PluginCommand = cmd({ global: Boolean(args.global), force: Boolean(args.force), }) - let ok = true - - await Instance.provide({ - directory: process.cwd(), - fn: async () => { - ok = await run({ - vcs: Instance.project.vcs, - worktree: Instance.worktree, - directory: Instance.directory, - }) - }, - }) + + const ctx = yield* InstanceRef + if (!ctx) return + const ok = yield* Effect.promise(() => + run({ + vcs: ctx.project.vcs, + worktree: ctx.worktree, + directory: ctx.directory, + }), + ) outro("Done") if (!ok) process.exitCode = 1 - }, + }), }) diff --git a/packages/opencode/src/cli/effect-cmd.ts b/packages/opencode/src/cli/effect-cmd.ts index cc4dd2ed7..29f750d16 100644 --- a/packages/opencode/src/cli/effect-cmd.ts +++ b/packages/opencode/src/cli/effect-cmd.ts @@ -31,6 +31,7 @@ export const fail = (message: string, exitCode = 1) => Effect.fail(new CliError( */ export const effectCmd = <Args, A>(opts: { command: string | readonly string[] + aliases?: string | readonly string[] describe: string | false builder?: (yargs: Argv) => Argv<Args> /** Defaults to process.cwd(). Override for commands that take a directory positional. */ @@ -39,6 +40,7 @@ export const effectCmd = <Args, A>(opts: { }) => cmd<{}, Args>({ command: opts.command, + aliases: opts.aliases, describe: opts.describe, builder: opts.builder as never, async handler(rawArgs) { |
