File tree 3 files changed +16
-3
lines changed
3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
11
11
handleInspectCommand ,
12
12
handleShowLogsCommand ,
13
13
} from "./logs"
14
- import { context , debug } from "./utils"
14
+ import { context , debug , getQueryValue } from "./utils"
15
15
import {
16
16
CoderWorkspacesProvider ,
17
17
rebuildWorkspace ,
@@ -43,8 +43,7 @@ export const uriHandler: vscode.UriHandler = {
43
43
debug ( `Handling URI: ${ uri } ` )
44
44
switch ( action ) {
45
45
case "open-workspace" : {
46
- const version = Array . isArray ( query . version ) ? query . version [ 0 ] : query . version
47
- return preflight ( version ) . then ( ( ) => openWorkspace ( resource ) )
46
+ return preflight ( getQueryValue ( query . version ) ) . then ( ( ) => openWorkspace ( resource ) )
48
47
}
49
48
default :
50
49
vscode . window . showErrorMessage ( `Unknown action "${ action } "` )
Original file line number Diff line number Diff line change @@ -86,4 +86,11 @@ suite("Utils", () => {
86
86
assert . strictEqual ( content2 , "archive content\n" )
87
87
}
88
88
} )
89
+
90
+ test ( "getQueryValue" , ( ) => {
91
+ assert . strictEqual ( utils . getQueryValue ( undefined ) , undefined )
92
+ assert . strictEqual ( utils . getQueryValue ( "foo" ) , "foo" )
93
+ assert . strictEqual ( utils . getQueryValue ( [ "bar" ] ) , "bar" )
94
+ assert . strictEqual ( utils . getQueryValue ( [ "bazzle" , "qux" ] ) , "bazzle" )
95
+ } )
89
96
} )
Original file line number Diff line number Diff line change @@ -204,3 +204,10 @@ export const getAssetUrl = (version: string): string => {
204
204
? `https://github.com/cdr/coder-cli/releases/${ version } /download/${ assetFilename } `
205
205
: `https://github.com/cdr/coder-cli/releases/download/${ version } /${ assetFilename } `
206
206
}
207
+
208
+ /**
209
+ * Get the first or only value from a query parameter.
210
+ */
211
+ export const getQueryValue = ( val : string [ ] | string | undefined ) : string | undefined => {
212
+ return Array . isArray ( val ) ? val [ 0 ] : val
213
+ }
You can’t perform that action at this time.
0 commit comments