22
33import * as vscode from "vscode"
44import { CoderHelpProvider } from "./help"
5- import * as which from "which"
65
76import {
87 CoderWorkspacesProvider ,
@@ -17,7 +16,7 @@ import {
1716 handleInspectCommand ,
1817 handleShowLogsCommand ,
1918} from "./logs"
20- import { execCombined } from "./utils"
19+ import { execCombined , binaryExists } from "./utils"
2120
2221export function activate ( context : vscode . ExtensionContext ) {
2322 preflightCheckCoderInstalled ( )
@@ -52,31 +51,33 @@ export function activate(context: vscode.ExtensionContext) {
5251
5352export const outputChannel = vscode . window . createOutputChannel ( "Coder" )
5453
55- const preflightCheckCoderInstalled = ( ) => {
56- which ( "coder" , ( err : any ) => {
57- if ( err ) {
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- } )
54+ const preflightCheckCoderInstalled = async ( ) => {
55+ const coderExists = await binaryExists ( "coder" )
56+ if ( coderExists ) {
57+ return
58+ }
59+ const brewExists = await binaryExists ( "brew" )
60+ if ( ! brewExists ) {
61+ vscode . window . showErrorMessage (
62+ `"coder" CLI not found in $PATH. Please follow the install and authentication [instructions here](https://coder.com/docs/cli/installation).` ,
63+ "Dismiss" ,
64+ )
65+ } else {
66+ const action = await vscode . window . showErrorMessage ( `"coder" CLI not found in $PATH` , "Install with `brew`" )
67+ if ( action ) {
68+ outputChannel . show ( )
69+ const cmd = "brew install cdr/coder/coder-cli"
70+ outputChannel . appendLine ( cmd )
71+ const output = await execCombined ( cmd )
72+ outputChannel . appendLine ( output . stderr )
73+ const coderExists = await binaryExists ( "coder" )
74+ if ( coderExists ) {
75+ outputChannel . appendLine (
76+ 'Installation successful.\nACTION REQUIRED: run "coder login [https://coder.domain.com]"' ,
77+ )
78+ } else {
79+ outputChannel . appendLine ( `Install failed. "coder" still not found in $PATH.` )
80+ }
8081 }
81- } )
82+ }
8283}
0 commit comments