MCPcopy Index your code
hub / github.com/anomalyco/opencode / executeUninstall

Function executeUninstall

packages/opencode/src/cli/cmd/uninstall.ts:144–233  ·  view source on GitHub ↗
(method: Installation.Method, targets: RemovalTargets)

Source from the content-addressed store, hash-verified

142}
143
144async function executeUninstall(method: Installation.Method, targets: RemovalTargets) {
145 const spinner = prompts.spinner()
146 const errors: string[] = []
147
148 for (const dir of targets.directories) {
149 if (dir.keep) {
150 prompts.log.step(`Skipping ${dir.label} (--keep-${dir.label.toLowerCase()})`)
151 continue
152 }
153
154 const exists = await fs
155 .access(dir.path)
156 .then(() => true)
157 .catch(() => false)
158 if (!exists) continue
159
160 spinner.start(`Removing ${dir.label}...`)
161 const err = await fs.rm(dir.path, { recursive: true, force: true }).catch((e) => e)
162 if (err) {
163 spinner.stop(`Failed to remove ${dir.label}`, 1)
164 errors.push(`${dir.label}: ${err.message}`)
165 continue
166 }
167 spinner.stop(`Removed ${dir.label}`)
168 }
169
170 if (targets.shellConfig) {
171 spinner.start("Cleaning shell config...")
172 const err = await cleanShellConfig(targets.shellConfig).catch((e) => e)
173 if (err) {
174 spinner.stop("Failed to clean shell config", 1)
175 errors.push(`Shell config: ${err.message}`)
176 } else {
177 spinner.stop("Cleaned shell config")
178 }
179 }
180
181 if (method !== "curl" && method !== "unknown") {
182 const cmds: Record<string, string[]> = {
183 npm: ["npm", "uninstall", "-g", "opencode-ai"],
184 pnpm: ["pnpm", "uninstall", "-g", "opencode-ai"],
185 bun: ["bun", "remove", "-g", "opencode-ai"],
186 yarn: ["yarn", "global", "remove", "opencode-ai"],
187 brew: ["brew", "uninstall", "opencode"],
188 choco: ["choco", "uninstall", "opencode"],
189 scoop: ["scoop", "uninstall", "opencode"],
190 }
191
192 const cmd = cmds[method]
193 if (cmd) {
194 spinner.start(`Running ${cmd.join(" ")}...`)
195 const result = await Process.run(method === "choco" ? ["choco", "uninstall", "opencode", "-y", "-r"] : cmd, {
196 nothrow: true,
197 })
198 if (result.code !== 0) {
199 spinner.stop(`Package manager uninstall failed: exit code ${result.code}`, 1)
200 const text = `${result.stdout.toString("utf8")}\n${result.stderr.toString("utf8")}`
201 if (method === "choco" && text.includes("not running from an elevated command shell")) {

Callers 1

uninstall.tsFile · 0.85

Calls 6

cleanShellConfigFunction · 0.85
pushMethod · 0.80
startMethod · 0.45
stopMethod · 0.45
runMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected