From 6130c89ccec5262c25b91b3226a6ef2240bfde3b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 22 Dec 2018 20:44:41 +0100 Subject: [PATCH] PowerShell: remove aliases, use their real commands instead This patch replaces PowerShell aliases for their real commands, see https://blogs.technet.microsoft.com/heyscriptingguy/2012/04/21/when-you-should-use-powershell-aliases/ For example; - use `Get-Location` instead of `pwd` - use `Set-Location` instead of `cd` - use `ForEach-Object` instead of the `%` shorthand - use `Write-Output` instead of `echo` Signed-off-by: Sebastiaan van Stijn --- hack/ci/windows.ps1 | 14 +++++++------- hack/make.ps1 | 10 +++++----- hack/make/.go-autogen.ps1 | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hack/ci/windows.ps1 b/hack/ci/windows.ps1 index ff6459543a..4443019584 100644 --- a/hack/ci/windows.ps1 +++ b/hack/ci/windows.ps1 @@ -256,7 +256,7 @@ Try { Get-ChildItem Env: | Out-String # PR - if (-not ($null -eq $env:PR)) { echo "INFO: PR#$env:PR (https://github.com/docker/docker/pull/$env:PR)" } + if (-not ($null -eq $env:PR)) { Write-Output "INFO: PR#$env:PR (https://github.com/docker/docker/pull/$env:PR)" } # Make sure docker is installed if ($null -eq (Get-Command "docker" -ErrorAction SilentlyContinue)) { Throw "ERROR: docker is not installed or not found on path" } @@ -291,12 +291,12 @@ Try { } # Make sure we start at the root of the sources - cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker" - Write-Host -ForegroundColor Green "INFO: Running in $(pwd)" + Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker" + Write-Host -ForegroundColor Green "INFO: Running in $(Get-Location)" # Make sure we are in repo if (-not (Test-Path -PathType Leaf -Path ".\Dockerfile.windows")) { - Throw "$(pwd) does not contain Dockerfile.windows!" + Throw "$(Get-Location) does not contain Dockerfile.windows!" } Write-Host -ForegroundColor Green "INFO: docker/docker repository was found" @@ -835,7 +835,7 @@ Try { "`$env`:PATH`='c`:\target;'+`$env:PATH`; `$env:DOCKER_HOST`='tcp`://'+(ipconfig | select -last 1).Substring(39)+'`:2357'; c:\target\runIntegrationCLI.ps1" | Out-Host } ) } else { Write-Host -ForegroundColor Green "INFO: Integration tests being run from the host:" - cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli" + Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli" $env:DOCKER_HOST=$DASHH_CUT $env:PATH="$env:TEMP\binary;$env:PATH;" # Force to use the test binaries, not the host ones. Write-Host -ForegroundColor Green "INFO: $c" @@ -901,7 +901,7 @@ Try { $c += "`"-test.timeout`" " + "`"200m`" " Write-Host -ForegroundColor Green "INFO: LCOW Integration tests being run from the host:" - cd "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli" + Set-Location "$env:SOURCES_DRIVE`:\$env:SOURCES_SUBDIR\src\github.com\docker\docker\integration-cli" Write-Host -ForegroundColor Green "INFO: $c" Write-Host -ForegroundColor Green "INFO: DOCKER_HOST at $DASHH_CUT" # Explicit to not use measure-command otherwise don't get output as it goes @@ -988,7 +988,7 @@ Finally { Copy-Item "$env:TEMP\dut.err" "$TEMPORIG\CIDUT.log" -Force -ErrorAction SilentlyContinue } - cd "$env:SOURCES_DRIVE\$env:SOURCES_SUBDIR" -ErrorAction SilentlyContinue + Set-Location "$env:SOURCES_DRIVE\$env:SOURCES_SUBDIR" -ErrorAction SilentlyContinue Nuke-Everything $Dur=New-TimeSpan -Start $StartTime -End $(Get-Date) Write-Host -ForegroundColor $FinallyColour "`nINFO: executeCI.ps1 exiting at $(date). Duration $dur`n" diff --git a/hack/make.ps1 b/hack/make.ps1 index 4ee47ba847..9d6346b83c 100644 --- a/hack/make.ps1 +++ b/hack/make.ps1 @@ -218,7 +218,7 @@ Function Validate-DCO($headCommit, $upstreamCommit) { if ($LASTEXITCODE -ne 0) { Throw "Failed git log --format" } $commits = $($commits -split '\s+' -match '\S') $badCommits=@() - $commits | %{ + $commits | ForEach-Object{ # Skip commits with no content such as merge commits etc if ($(git log -1 --format=format: --name-status $_).Length -gt 0) { # Ignore exit code on next call - always process regardless @@ -244,7 +244,7 @@ Function Validate-PkgImports($headCommit, $upstreamCommit) { # Get a list of go source-code files which have changed under pkg\. Ignore exit code on next call - always process regardless $files=@(); $files = Invoke-Expression "git diff $upstreamCommit...$headCommit --diff-filter=ACMR --name-only -- `'pkg\*.go`'" - $badFiles=@(); $files | %{ + $badFiles=@(); $files | ForEach-Object{ $file=$_ # For the current changed file, get its list of dependencies, sorted and uniqued. $imports = Invoke-Expression "go list -e -f `'{{ .Deps }}`' $file" @@ -255,13 +255,13 @@ Function Validate-PkgImports($headCommit, $upstreamCommit) { -NotMatch "^github.com/docker/docker/vendor" ` -Match "^github.com/docker/docker" ` -Replace "`n", "" - $imports | % { $badFiles+="$file imports $_`n" } + $imports | ForEach-Object{ $badFiles+="$file imports $_`n" } } if ($badFiles.Length -eq 0) { Write-Host 'Congratulations! ".\pkg\*.go" is safely isolated from internal code.' } else { $e = "`nThese files import internal code: (either directly or indirectly)`n" - $badFiles | %{ $e+=" - $_"} + $badFiles | ForEach-Object{ $e+=" - $_"} Throw $e } } @@ -297,7 +297,7 @@ Function Validate-GoFormat($headCommit, $upstreamCommit) { Write-Host 'Congratulations! All Go source files are properly formatted.' } else { $e = "`nThese files are not properly gofmt`'d:`n" - $badFiles | %{ $e+=" - $_`n"} + $badFiles | ForEach-Object{ $e+=" - $_`n"} $e+= "`nPlease reformat the above files using `"gofmt -s -w`" and commit the result." Throw $e } diff --git a/hack/make/.go-autogen.ps1 b/hack/make/.go-autogen.ps1 index 541d775417..35c311bb2a 100644 --- a/hack/make/.go-autogen.ps1 +++ b/hack/make/.go-autogen.ps1 @@ -55,7 +55,7 @@ const ( ' # Write the file without BOM - $outputFile="$(pwd)\dockerversion\version_autogen.go" + $outputFile="$(Get-Location)\dockerversion\version_autogen.go" if (Test-Path $outputFile) { Remove-Item $outputFile } [System.IO.File]::WriteAllText($outputFile, $fileContents, (New-Object System.Text.UTF8Encoding($False)))