refactor(cli): convert plugin command to effectCmd (#25473)

This commit is contained in:
Kit Langton
2026-05-02 17:55:13 -04:00
committed by GitHub
parent e318e173d8
commit 0c816eb4b1
2 changed files with 20 additions and 21 deletions
+18 -21
View File
@@ -1,16 +1,16 @@
import { intro, log, outro, spinner } from "@clack/prompts" import { intro, log, outro, spinner } from "@clack/prompts"
import type { Argv } from "yargs" import { Effect } from "effect"
import { ConfigPaths } from "@/config/paths" import { ConfigPaths } from "@/config/paths"
import { Global } from "@opencode-ai/core/global" import { Global } from "@opencode-ai/core/global"
import { installPlugin, patchPluginConfig, readPluginManifest } from "../../plugin/install" import { installPlugin, patchPluginConfig, readPluginManifest } from "../../plugin/install"
import { resolvePluginTarget } from "../../plugin/shared" import { resolvePluginTarget } from "../../plugin/shared"
import { Instance } from "../../project/instance"
import { errorMessage } from "../../util/error" import { errorMessage } from "../../util/error"
import { Filesystem } from "@/util/filesystem" import { Filesystem } from "@/util/filesystem"
import { Process } from "@/util/process" import { Process } from "@/util/process"
import { UI } from "../ui" import { UI } from "../ui"
import { cmd } from "./cmd" import { effectCmd } from "../effect-cmd"
import { InstanceRef } from "@/effect/instance-ref"
type Spin = { type Spin = {
start: (msg: string) => void 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>", command: "plugin <module>",
aliases: ["plug"], aliases: ["plug"],
describe: "install plugin and update config", describe: "install plugin and update config",
builder: (yargs: Argv) => { builder: (yargs) =>
return yargs yargs
.positional("module", { .positional("module", {
type: "string", type: "string",
describe: "npm module name", describe: "npm module name",
@@ -196,9 +196,8 @@ export const PluginCommand = cmd({
type: "boolean", type: "boolean",
default: false, default: false,
describe: "replace existing plugin version", describe: "replace existing plugin version",
}) }),
}, handler: Effect.fn("Cli.plug")(function* (args) {
handler: async (args) => {
const mod = String(args.module ?? "").trim() const mod = String(args.module ?? "").trim()
if (!mod) { if (!mod) {
UI.error("module is required") UI.error("module is required")
@@ -214,20 +213,18 @@ export const PluginCommand = cmd({
global: Boolean(args.global), global: Boolean(args.global),
force: Boolean(args.force), force: Boolean(args.force),
}) })
let ok = true
await Instance.provide({ const ctx = yield* InstanceRef
directory: process.cwd(), if (!ctx) return
fn: async () => { const ok = yield* Effect.promise(() =>
ok = await run({ run({
vcs: Instance.project.vcs, vcs: ctx.project.vcs,
worktree: Instance.worktree, worktree: ctx.worktree,
directory: Instance.directory, directory: ctx.directory,
}) }),
}, )
})
outro("Done") outro("Done")
if (!ok) process.exitCode = 1 if (!ok) process.exitCode = 1
}, }),
}) })
+2
View File
@@ -31,6 +31,7 @@ export const fail = (message: string, exitCode = 1) => Effect.fail(new CliError(
*/ */
export const effectCmd = <Args, A>(opts: { export const effectCmd = <Args, A>(opts: {
command: string | readonly string[] command: string | readonly string[]
aliases?: string | readonly string[]
describe: string | false describe: string | false
builder?: (yargs: Argv) => Argv<Args> builder?: (yargs: Argv) => Argv<Args>
/** Defaults to process.cwd(). Override for commands that take a directory positional. */ /** Defaults to process.cwd(). Override for commands that take a directory positional. */
@@ -39,6 +40,7 @@ export const effectCmd = <Args, A>(opts: {
}) => }) =>
cmd<{}, Args>({ cmd<{}, Args>({
command: opts.command, command: opts.command,
aliases: opts.aliases,
describe: opts.describe, describe: opts.describe,
builder: opts.builder as never, builder: opts.builder as never,
async handler(rawArgs) { async handler(rawArgs) {