@@ -7,6 +7,15 @@ import * as nodeWhich from "which"
7
7
import { requestResponse } from "./request"
8
8
import { context , debug , extractTar , extractZip , getAssetUrl , onLine , outputChannel , wrapExit } from "./utils"
9
9
10
+ /**
11
+ * Options for installing and authenticating the Coder CLI.
12
+ */
13
+ export interface CoderOptions {
14
+ accessUri ?: string
15
+ token ?: string
16
+ version ?: string
17
+ }
18
+
10
19
/**
11
20
* Return "true" if the binary is found in $PATH.
12
21
*/
@@ -17,13 +26,13 @@ export const binaryExists = async (bin: string): Promise<boolean> => {
17
26
}
18
27
19
28
/**
20
- * Run a command with the Coder CLI after making sure it is installed. On
21
- * success stdout is returned. On failure the error will include stderr in the
22
- * message.
29
+ * Run a command with the Coder CLI after making sure it is installed and
30
+ * authenticated. On success stdout is returned. On failure the error will
31
+ * include stderr in the message.
23
32
*/
24
- export const execCoder = async ( command : string ) : Promise < string > => {
33
+ export const execCoder = async ( command : string , opts ?: CoderOptions ) : Promise < string > => {
25
34
debug ( `Run command: ${ command } ` )
26
- const coderBinary = await preflight ( )
35
+ const coderBinary = await preflight ( opts ?. version )
27
36
const output = await promisify ( cp . exec ) ( coderBinary + " " + command )
28
37
return output . stdout
29
38
}
@@ -40,9 +49,6 @@ const coderInvocation = (): { cmd: string; args: string[] } => {
40
49
return { cmd : process . platform === "win32" ? "coder.exe" : "coder" , args : [ ] }
41
50
}
42
51
43
- /** Only one preflight request at a time. */
44
- let _preflight : Promise < string > | undefined
45
-
46
52
/**
47
53
* Download the Coder CLI to the provided location and return that location.
48
54
*/
@@ -178,13 +184,13 @@ export const maybeInstall = async (version: string): Promise<string> => {
178
184
}
179
185
}
180
186
187
+ /** Only one preflight request at a time. */
188
+ let _preflight : Promise < string > | undefined
189
+
181
190
/**
182
- * Check that Coder is installed and authenticated. If not try installing and
183
- * authenticating.
191
+ * Check that Coder is installed. If not try installing.
184
192
*
185
193
* Return the appropriate invocation for the binary.
186
- *
187
- * @TODO Implement authentication portion.
188
194
*/
189
195
export const preflight = async ( version = "latest" ) : Promise < string > => {
190
196
if ( ! _preflight ) {
0 commit comments