Просмотр исходного кода

Add --method option to upgrade command for manual installation method selection

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <[email protected]>
Dax Raad 8 месяцев назад
Родитель
Сommit
59f0004d34

+ 15 - 7
packages/opencode/src/cli/cmd/upgrade.ts

@@ -7,17 +7,25 @@ export const UpgradeCommand = {
   command: "upgrade [target]",
   describe: "upgrade opencode to the latest version or a specific version",
   builder: (yargs: Argv) => {
-    return yargs.positional("target", {
-      describe: "specific version to upgrade to (e.g., '0.1.48' or 'v0.1.48')",
-      type: "string",
-    })
+    return yargs
+      .positional("target", {
+        describe: "specific version to upgrade to (e.g., '0.1.48' or 'v0.1.48')",
+        type: "string",
+      })
+      .option("method", {
+        alias: "m",
+        describe: "installation method to use (curl, npm, pnpm, bun, brew)",
+        type: "string",
+        choices: ["curl", "npm", "pnpm", "bun", "brew"],
+      })
   },
-  handler: async (args: { target?: string }) => {
+  handler: async (args: { target?: string; method?: string }) => {
     UI.empty()
     UI.println(UI.logo("  "))
     UI.empty()
     prompts.intro("Upgrade")
-    const method = await Installation.method()
+    const detectedMethod = await Installation.method()
+    const method = (args.method as Installation.Method) ?? detectedMethod
     if (method === "unknown") {
       prompts.log.error(
         `opencode is installed to ${process.execPath} and seems to be managed by a package manager`,
@@ -25,7 +33,7 @@ export const UpgradeCommand = {
       prompts.outro("Done")
       return
     }
-    prompts.log.info("Installed via " + method)
+    prompts.log.info("Using method: " + method)
     const target = args.target ?? (await Installation.latest())
     prompts.log.info(`From ${Installation.VERSION} → ${target}`)
     const spinner = prompts.spinner()

+ 10 - 1
packages/opencode/src/installation/index.ts

@@ -3,12 +3,15 @@ import { $ } from "bun"
 import { z } from "zod"
 import { NamedError } from "../util/error"
 import { Bus } from "../bus"
+import { Log } from "../util/log"
 
 declare global {
   const OPENCODE_VERSION: string
 }
 
 export namespace Installation {
+  const log = Log.create({ service: "installation" })
+
   export type Method = Awaited<ReturnType<typeof method>>
 
   export const Event = {
@@ -102,8 +105,8 @@ export namespace Installation {
       switch (method) {
         case "curl":
           return $`curl -fsSL https://opencode.ai/install | bash`.env({
-            VERSION: target,
             ...process.env,
+            VERSION: target,
           })
         case "npm":
           return $`npm install -g opencode-ai@${target}`
@@ -118,6 +121,12 @@ export namespace Installation {
       }
     })()
     const result = await cmd.quiet().throws(false)
+    log.info("upgraded", {
+      method,
+      target,
+      stdout: result.stdout.toString(),
+      stderr: result.stderr.toString(),
+    })
     if (result.exitCode !== 0)
       throw new UpgradeFailedError({
         stderr: result.stderr.toString("utf8"),