diff --git a/package.json b/package.json index f19e38a..2b806ba 100644 --- a/package.json +++ b/package.json @@ -239,6 +239,11 @@ "type": "string", "default": "", "description": "Location of Azure REST specification." + }, + "ansible.targetName": { + "type": "string", + "default": "", + "descritption": "Specify which folder will be used on the target." } } } diff --git a/src/constants.ts b/src/constants.ts index 57c25e3..6ee04fa 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -3,12 +3,14 @@ export class Constants { public static LineSeperator = Array(50).join('='); public static AzureAccountExtensionId = 'ms-vscode.azure-account'; public static DockerImageName = 'microsoft/ansible:latest'; + public static TargetName = '${workspaceFolderBasename}'; public static AnsibleTerminalName = 'Ansible'; public static UserAgentName = 'VSCODEEXT_USER_AGENT'; public static Config_cloudShellConfirmed = 'cloudShellConfirmed'; public static Config_credentialConfigured = 'credentialsConfigured'; public static Config_credentialsFile = 'credentialsFile'; public static Config_dockerImage = 'dockerImage'; + public static Config_targetName = 'targetName'; public static Config_useWSL = 'useWSL'; public static Config_terminalInitCommand = 'terminalInitCommand'; public static Config_fileCopyConfig = 'fileCopyConfig'; @@ -31,4 +33,4 @@ export enum CloudShellConnectionStatus { Init = 'init', Succeeded = 'succeeded', Failed = 'failed' -} \ No newline at end of file +} diff --git a/src/dockerRunner.ts b/src/dockerRunner.ts index 454f5ef..aabf1c8 100644 --- a/src/dockerRunner.ts +++ b/src/dockerRunner.ts @@ -12,12 +12,19 @@ import { TerminalBaseRunner } from './terminalBaseRunner'; import * as fsExtra from 'fs-extra'; import * as child_process from 'child_process'; - export class DockerRunner extends TerminalBaseRunner { constructor(outputChannel: vscode.OutputChannel) { super(outputChannel); } + private getTargetName(): string { + let customTarget = utilities.getCodeConfiguration('ansible', Constants.Config_targetName); + if (!customTarget) { + customTarget = Constants.TargetName; + } + return customTarget; + } + protected getCmds(playbook: string, envs: string[], terminalId: string): string[] { var cmdsToTerminal = []; let cmd: string = utilities.getCodeConfiguration(null, Constants.Config_terminalInitCommand); @@ -25,16 +32,19 @@ export class DockerRunner extends TerminalBaseRunner { var sourcePath = path.dirname(playbook); var targetPath = '/playbook'; var targetPlaybook = targetPath + '/' + path.basename(playbook); + targetPlaybook = path.relative(sourcePath, playbook); + targetPlaybook = targetPlaybook.replace(/\\/g, '/'); if (vscode.workspace.workspaceFolders) { sourcePath = vscode.workspace.workspaceFolders[0].uri.fsPath; targetPath = '/' + vscode.workspace.name; targetPlaybook = path.relative(sourcePath, playbook); targetPlaybook = targetPlaybook.replace(/\\/g, '/'); - } + } + if (cmd === "default" || cmd === '') { - cmd = "docker run --rm -it -v \"" + sourcePath + ":" + targetPath + "\"" + - " --workdir \"" + targetPath + "\"" + " --name " + terminalId; + cmd = "docker run --rm -it -v \"" + sourcePath + ":/" + this.getTargetName() + "\"" + + " --workdir \"/" + this.getTargetName() + "\"" + " --name " + terminalId; // add credential envs if any if (envs) { @@ -135,4 +145,4 @@ export class DockerRunner extends TerminalBaseRunner { } return customDocker; } -} \ No newline at end of file +}