Skip to content

Commit 1cd1225

Browse files
committed
feat: expose action button to install with brew
1 parent de91bf0 commit 1cd1225

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/extension.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
handleInspectCommand,
1818
handleShowLogsCommand,
1919
} from "./logs"
20+
import { execCombined } from "./utils"
2021

2122
export function activate(context: vscode.ExtensionContext) {
2223
preflightCheckCoderInstalled()
@@ -49,13 +50,33 @@ export function activate(context: vscode.ExtensionContext) {
4950
vscode.workspace.registerTextDocumentContentProvider("coder-inspect", coderWorkspaceInspectDocumentProvider)
5051
}
5152

53+
export const outputChannel = vscode.window.createOutputChannel("Coder")
54+
5255
const preflightCheckCoderInstalled = () => {
5356
which("coder", (err: any) => {
5457
if (err) {
55-
vscode.window.showErrorMessage(
56-
`"coder" CLI not found in $PATH. Please follow the install and authentication instructions here: https://coder.com/docs/cli/installation`,
57-
"Dismiss",
58-
)
58+
which("brew", async (err: any) => {
59+
if (err) {
60+
vscode.window.showErrorMessage(
61+
`"coder" CLI not found in $PATH. Please follow the install and authentication [instructions here](https://coder.com/docs/cli/installation)`,
62+
"Dismiss",
63+
)
64+
} else {
65+
const action = await vscode.window.showErrorMessage(`"coder" CLI not found in $PATH`, "Install with `brew`")
66+
if (action) {
67+
outputChannel.show()
68+
const cmd = "brew install cdr/coder/coder-cli"
69+
outputChannel.appendLine(cmd)
70+
const output = await execCombined(cmd)
71+
outputChannel.appendLine(output.stderr)
72+
which("coder", err => err ? (
73+
outputChannel.appendLine(`Install failed. "coder" still not found in $PATH.`)
74+
) : (
75+
outputChannel.appendLine("Installation successful.\nACTION REQUIRED: run \"coder login [https://coder.domain.com]\"")
76+
))
77+
}
78+
}
79+
})
5980
}
6081
})
6182
}

src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export const exec = async (command: string): Promise<string> => {
1010
})
1111
}
1212

13+
export const execCombined = async (command: string): Promise<{stderr: string, stdout: string}> => {
14+
return new Promise((res, rej) => {
15+
cp.exec(command, (err, stdout, stderr) => (err ? rej(err) : res({stderr, stdout})))
16+
})
17+
}
18+
1319
export const execJSON = async <T>(command: string): Promise<T> => {
1420
const output = await exec(command)
1521
return JSON.parse(output)

0 commit comments

Comments
 (0)