-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathImageNameStep.ts
More file actions
37 lines (31 loc) · 1.7 KB
/
ImageNameStep.ts
File metadata and controls
37 lines (31 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardPromptStep } from "@microsoft/vscode-azext-utils";
import { URI, Utils } from "vscode-uri";
import { localize } from "../../../utils/localize";
import { IBuildImageInAzureContext } from "./IBuildImageInAzureContext";
export class ImageNameStep extends AzureWizardPromptStep<IBuildImageInAzureContext> {
public async prompt(context: IBuildImageInAzureContext): Promise<void> {
const suggestedImageName = await getSuggestedName(context, context.dockerFilePath);
context.imageName = await context.ui.showInputBox({
prompt: localize('imageNamePrompt', 'Enter a name for the image'),
value: suggestedImageName ? localize('dockerfilePlaceholder', suggestedImageName) : ''
});
}
public shouldPrompt(context: IBuildImageInAzureContext): boolean {
return !context.imageName;
}
}
async function getSuggestedName(context: IBuildImageInAzureContext, dockerFilePath: string): Promise<string | undefined> {
let suggestedImageName: string | undefined;
suggestedImageName = Utils.dirname(URI.parse(dockerFilePath)).path.split('/').pop();
if (suggestedImageName === '') {
if (context.rootFolder) {
suggestedImageName = Utils.basename(context.rootFolder.uri).toLowerCase().replace(/\s/g, '');
}
}
suggestedImageName += ":{{.Run.ID}}";
return suggestedImageName;
}