handle exit codes and documentation changes

This commit is contained in:
mahim23 2018-09-16 14:41:29 +05:30
parent ed98f19394
commit a1d372d580
1 changed files with 23 additions and 10 deletions

33
run.ps1
View File

@ -52,36 +52,41 @@ function Start-Embark {
foreach ($env_var in "LANG", "LANGUAGE", "LC_ALL", "TERM") { foreach ($env_var in "LANG", "LANGUAGE", "LC_ALL", "TERM") {
if (Test-Path "Env:$env_var") { if (Test-Path "Env:$env_var") {
$run_opts = $run_opts + "-e" + "$env_var" $run_opts = $run_opts + @("-e", "$env_var")
} }
} }
if ($EMBARK_DOCKER_RUN_RM -eq $true) { if ($EMBARK_DOCKER_RUN_RM -eq $true) {
$run_opts = $run_opts + "--rm" $run_opts = $run_opts + @("--rm")
} }
$OldErrorActionPreference = $ErrorActionPreference $OldErrorActionPreference = $ErrorActionPreference
# 'Continue' - Preference for printing errors and continuing the execution in case of non-terminating errors.
$ErrorActionPreference = 'Continue' $ErrorActionPreference = 'Continue'
function Cleanup { function Cleanup ( [parameter( Mandatory = $false )] [int] $RetVal) {
$retval = $lastexitcode Remove-Item -Path Function:\Set-Value
Remove-Item -Path Function:\Confirm-Docker Remove-Item -Path Function:\Confirm-Docker
Remove-Item -Path Function:\Cleanup Remove-Item -Path Function:\Cleanup
$ErrorActionPreference = $OldErrorActionPreference $ErrorActionPreference = $OldErrorActionPreference
return $retval $Global:LASTEXITCODE = $RetVal
return
} }
function Confirm-Docker () { function Confirm-Docker () {
if (-not (Get-Command docker -errorAction SilentlyContinue)) { if (-not (Get-Command docker -errorAction SilentlyContinue)) {
"Error: the command ``docker`` must be in a path on `$PATH or aliased" Write-Host "Error: " -ForegroundColor Red -NoNewline
Write-Host "the command ``docker`` must be in a path on `$PATH or aliased"
return 127 return 127
} }
return 0
} }
Confirm-Docker $docker_return_code = Confirm-Docker
if (-not($?)) { if ($docker_return_code) {
return Cleanup return Cleanup -RetVal $docker_return_code
} }
$had_run_opts = $false $had_run_opts = $false
@ -132,9 +137,10 @@ function Start-Embark {
$run_script = Get-Content $EMBARK_DOCKER_RUN $run_script = Get-Content $EMBARK_DOCKER_RUN
# " doesn't directly get passed to the container so has to be replaced by \" # " doesn't get passed to the container so has to be replaced by \"
$run_script = $run_script -join "`n" -replace '"', '\"' $run_script = $run_script -join "`n" -replace '"', '\"'
# do not alter indentation, tabs in lines below
$run_script = "exec bash -${i_flag}s `$(tty) ${cmd} << 'RUN' $run_script = "exec bash -${i_flag}s `$(tty) ${cmd} << 'RUN'
__tty=`$1 __tty=`$1
shift shift
@ -145,6 +151,8 @@ SCRIPT
chmod +x `$script chmod +x `$script
exec `$script `$@ < `$__tty exec `$script `$@ < `$__tty
RUN" RUN"
# do not alter indentation, tabs in lines above
$cmd = ("bash", "-${i_flag}c", "$run_script") $cmd = ("bash", "-${i_flag}c", "$run_script")
} }
@ -152,10 +160,15 @@ RUN"
docker run $opts docker run $opts
if (-not $?) {
return Cleanup -RetVal 1
}
return Cleanup return Cleanup
} }
# Invokes Start-Embark only if the source is this script.
if ($MyInvocation.InvocationName.EndsWith($MyInvocation.MyCommand.Name)) { if ($MyInvocation.InvocationName.EndsWith($MyInvocation.MyCommand.Name)) {
Start-Embark @args Start-Embark @args
} }