2025-06-15 02:05:41 +00:00
|
|
|
import type { Argv } from "yargs"
|
|
|
|
|
import { UI } from "../ui"
|
|
|
|
|
import * as prompts from "@clack/prompts"
|
2025-06-17 04:07:17 +00:00
|
|
|
import { Installation } from "../../installation"
|
2025-06-15 02:05:41 +00:00
|
|
|
|
|
|
|
|
export const UpgradeCommand = {
|
|
|
|
|
command: "upgrade [target]",
|
2025-06-19 20:28:03 +00:00
|
|
|
describe: "upgrade opencode to the latest version or a specific version",
|
2025-06-15 02:05:41 +00:00
|
|
|
builder: (yargs: Argv) => {
|
|
|
|
|
return yargs.positional("target", {
|
2025-06-19 20:28:03 +00:00
|
|
|
describe: "specific version to upgrade to (e.g., '0.1.48' or 'v0.1.48')",
|
2025-06-15 02:05:41 +00:00
|
|
|
type: "string",
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handler: async (args: { target?: string }) => {
|
|
|
|
|
UI.empty()
|
|
|
|
|
UI.println(UI.logo(" "))
|
|
|
|
|
UI.empty()
|
2025-06-15 17:10:58 +00:00
|
|
|
prompts.intro("Upgrade")
|
2025-06-17 04:07:17 +00:00
|
|
|
const method = await Installation.method()
|
|
|
|
|
if (method === "unknown") {
|
2025-06-15 02:05:41 +00:00
|
|
|
prompts.log.error(
|
|
|
|
|
`opencode is installed to ${process.execPath} and seems to be managed by a package manager`,
|
|
|
|
|
)
|
|
|
|
|
prompts.outro("Done")
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-06-17 04:07:17 +00:00
|
|
|
const target = args.target ?? (await Installation.latest())
|
2025-06-17 14:27:49 +00:00
|
|
|
prompts.log.info(`From ${Installation.VERSION} → ${target}`)
|
2025-06-17 04:07:17 +00:00
|
|
|
const spinner = prompts.spinner()
|
|
|
|
|
spinner.start("Upgrading...")
|
|
|
|
|
const err = await Installation.upgrade(method, target).catch((err) => err)
|
|
|
|
|
if (err) {
|
|
|
|
|
spinner.stop("Upgrade failed")
|
|
|
|
|
if (err instanceof Installation.UpgradeFailedError)
|
|
|
|
|
prompts.log.error(err.data.stderr)
|
|
|
|
|
else if (err instanceof Error) prompts.log.error(err.message)
|
|
|
|
|
prompts.outro("Done")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
spinner.stop("Upgrade complete")
|
|
|
|
|
prompts.outro("Done")
|
2025-06-15 02:05:41 +00:00
|
|
|
},
|
|
|
|
|
}
|