add config whether to check terraform exists in the path

This commit is contained in:
njucz 2019-10-30 15:54:10 +08:00 коммит произвёл mybayern1974
Родитель 696b76a278
Коммит ce6d0136ff
4 изменённых файлов: 33 добавлений и 2 удалений

Просмотреть файл

@ -51,6 +51,11 @@
],
"description": "Specifies terminal used to run Terraform commands. Valid settings are `cloudshell` or `integrated`."
},
"azureTerraform.checkTerraformCmd": {
"type": "boolean",
"default": "true",
"description": "Specifies whether or not check terraform installed in the PATH."
},
"azureTerraform.files": {
"type": "string",
"default": "**/*.{rb,sh,tf,tfvars,txt,yml}",

Просмотреть файл

@ -32,3 +32,11 @@ export function getLocationForTest(): string {
export function getImageNameForTest(): string {
return vscode.workspace.getConfiguration().get("azureTerraform.test.imageName");
}
export function getCheckTerraformCmd(): boolean {
return vscode.workspace.getConfiguration().get("azureTerraform.checkTerraformCmd");
}
export function setCheckTerraformCmd(checked: boolean): void {
vscode.workspace.getConfiguration().update("azureTerraform.checkTerraformCmd", checked);
}

Просмотреть файл

@ -6,12 +6,20 @@
"use strict";
import { executeCommand } from "./cpUtils";
import { openUrlHint } from "./uiUtils";
import * as settingUtils from "./settingUtils";
import { openUrlHintOrNotShowAgain } from "./uiUtils";
export async function checkTerraformInstalled(): Promise<void> {
if (!settingUtils.getCheckTerraformCmd()) {
return;
}
try {
await executeCommand("terraform", ["-v"], { shell: true });
} catch (error) {
openUrlHint("Terraform is not installed, please make sure Terraform is in the PATH environment variable.", "https://aka.ms/azTerraform-requirement");
openUrlHintOrNotShowAgain("Terraform is not installed, please make sure Terraform is in the PATH environment variable.",
"https://aka.ms/azTerraform-requirement",
() => {
settingUtils.setCheckTerraformCmd(false);
});
}
}

Просмотреть файл

@ -9,6 +9,15 @@ import * as opn from "opn";
import * as vscode from "vscode";
import { terraformChannel } from "../terraformChannel";
export async function openUrlHintOrNotShowAgain(message: string, url: string, notShowCallback: () => void): Promise<void> {
const response = await vscode.window.showInformationMessage(message, DialogOption.learnMore, DialogOption.notShownAgain);
if (response === DialogOption.learnMore && url) {
opn(url);
} else if (response === DialogOption.notShownAgain) {
notShowCallback();
}
}
export async function openUrlHint(message: string, url: string): Promise<void> {
const response = await vscode.window.showInformationMessage(message, DialogOption.learnMore, DialogOption.cancel);
if (response === DialogOption.learnMore && url) {
@ -58,6 +67,7 @@ export namespace DialogOption {
export const cancel: vscode.MessageItem = { title: "Cancel", isCloseAffordance: true };
export const open: vscode.MessageItem = { title: "Open" };
export const learnMore: vscode.MessageItem = { title: "Learn More" };
export const notShownAgain: vscode.MessageItem = { title: "Don't show again" };
}
export enum DialogType {