2
2
3
3
import * as vscode from "vscode"
4
4
import { CoderHelpProvider } from "./help"
5
- import * as which from "which"
6
5
7
6
import {
8
7
CoderWorkspacesProvider ,
@@ -17,7 +16,7 @@ import {
17
16
handleInspectCommand ,
18
17
handleShowLogsCommand ,
19
18
} from "./logs"
20
- import { execCombined } from "./utils"
19
+ import { execCombined , binaryExists } from "./utils"
21
20
22
21
export function activate ( context : vscode . ExtensionContext ) {
23
22
preflightCheckCoderInstalled ( )
@@ -52,31 +51,33 @@ export function activate(context: vscode.ExtensionContext) {
52
51
53
52
export const outputChannel = vscode . window . createOutputChannel ( "Coder" )
54
53
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
+ }
80
81
}
81
- } )
82
+ }
82
83
}
0 commit comments