@@ -17,17 +17,25 @@ import { functionExplorer } from '../functionsExplorer';
17
17
18
18
const imageRegex = RegExp ( '[^/]+\\.[^/.]+\\/([^/.]+)(?:\\/[\\w\\s._-]*([\\w\\s._-]))*(?::[a-z0-9\\.-]+)?$' ) ;
19
19
20
- async function functionBuilder ( image : string ) : Promise < ImageAndBuild > {
21
- const builder = await vscode . window . showInputBox ( {
20
+ async function showInputBox ( promptMessage : string , inputValidMessage : string ) : Promise < string > {
21
+ // eslint-disable-next-line no-return-await
22
+ return await vscode . window . showInputBox ( {
22
23
ignoreFocusOut : true ,
23
- prompt : 'Provide Buildpack builder, either an as a an image name or a mapping name.' ,
24
+ prompt : promptMessage ,
24
25
validateInput : ( value : string ) => {
25
26
if ( ! imageRegex . test ( value ) ) {
26
- return 'Provide full image name in the form [registry]/[namespace]/[name]:[tag]' ;
27
+ return inputValidMessage ;
27
28
}
28
29
return null ;
29
30
} ,
30
31
} ) ;
32
+ }
33
+
34
+ async function functionBuilder ( image : string ) : Promise < ImageAndBuild > {
35
+ const builder = await showInputBox (
36
+ 'Provide Buildpack builder, either an as a an image name or a mapping name.' ,
37
+ 'Provide full image name in the form [registry]/[namespace]/[name]:[tag]' ,
38
+ ) ;
31
39
if ( ! builder ) {
32
40
return null ;
33
41
}
@@ -50,24 +58,15 @@ async function functionImage(selectedFolderPick: vscode.Uri, skipBuilder?: boole
50
58
const imagePick =
51
59
imageList . length === 1
52
60
? imageList [ 0 ]
53
- : await vscode . window . showInputBox ( {
54
- ignoreFocusOut : true ,
55
- prompt : 'Provide full image name in the form [registry]/[namespace]/[name]:[tag]' ,
56
- validateInput : ( value : string ) => {
57
- if ( ! imageRegex . test ( value ) ) {
58
- return 'Provide full image name in the form [registry]/[namespace]/[name]:[tag]' ;
59
- }
60
- return null ;
61
- } ,
62
- } ) ;
61
+ : await showInputBox (
62
+ 'Provide full image name in the form [registry]/[namespace]/[name]:[tag]' ,
63
+ 'Provide full image name in the form [registry]/[namespace]/[name]:[tag]' ,
64
+ ) ;
63
65
if ( ! imagePick ) {
64
66
return null ;
65
67
}
66
68
if ( ! funcData ?. [ 0 ] ?. builder . trim ( ) && ! skipBuilder ) {
67
69
const builder = await functionBuilder ( imagePick ) ;
68
- if ( ! builder ) {
69
- return null ;
70
- }
71
70
return builder ;
72
71
}
73
72
return { image : imagePick } ;
@@ -84,7 +83,7 @@ async function pathFunction(): Promise<FolderPick> {
84
83
}
85
84
}
86
85
if ( folderPicks . length === 0 ) {
87
- const message = 'No project exit which contain func.yaml in it.' ;
86
+ const message = 'No project exist which contain func.yaml in it.' ;
88
87
telemetryLog ( 'func_yaml_not_found' , message ) ;
89
88
// eslint-disable-next-line @typescript-eslint/no-floating-promises
90
89
vscode . window . showInformationMessage ( message ) ;
@@ -98,20 +97,25 @@ async function pathFunction(): Promise<FolderPick> {
98
97
ignoreFocusOut : true ,
99
98
placeHolder : 'Select function' ,
100
99
} ) ;
101
- if ( ! selectedFolderPick ) {
102
- return null ;
103
- }
104
100
return selectedFolderPick ;
105
101
}
106
102
107
- export async function buildFunction ( context ?: FunctionNode ) : Promise < void > {
103
+ async function selectedFolder ( context ?: FunctionNode ) : Promise < FolderPick > {
108
104
let selectedFolderPick : FolderPick ;
109
105
if ( ! context ) {
110
106
selectedFolderPick = await pathFunction ( ) ;
111
107
if ( ! selectedFolderPick ) {
112
108
return null ;
113
109
}
114
110
}
111
+ return selectedFolderPick ;
112
+ }
113
+
114
+ export async function buildFunction ( context ?: FunctionNode ) : Promise < void > {
115
+ const selectedFolderPick : FolderPick = await selectedFolder ( context ) ;
116
+ if ( ! selectedFolderPick ) {
117
+ return null ;
118
+ }
115
119
const funcData = await functionImage ( context ? context . contextPath : selectedFolderPick . workspaceFolder . uri ) ;
116
120
if ( ! funcData ) {
117
121
return null ;
@@ -129,12 +133,9 @@ export async function buildFunction(context?: FunctionNode): Promise<void> {
129
133
}
130
134
131
135
export async function deployFunction ( context ?: FunctionNode ) : Promise < void > {
132
- let selectedFolderPick : FolderPick ;
133
- if ( ! context ) {
134
- selectedFolderPick = await pathFunction ( ) ;
135
- if ( ! selectedFolderPick ) {
136
- return null ;
137
- }
136
+ const selectedFolderPick : FolderPick = await selectedFolder ( context ) ;
137
+ if ( ! selectedFolderPick ) {
138
+ return null ;
138
139
}
139
140
const funcData = await functionImage ( context ? context . contextPath : selectedFolderPick . workspaceFolder . uri , true ) ;
140
141
if ( ! funcData ) {
0 commit comments