Skip to content

Instantly share code, notes, and snippets.

@ChlorideCull
Created January 24, 2020 12:30
Show Gist options
  • Save ChlorideCull/e77987789e96698ee75f18a11c5829c7 to your computer and use it in GitHub Desktop.
Save ChlorideCull/e77987789e96698ee75f18a11c5829c7 to your computer and use it in GitHub Desktop.
Random objects in returned array

Call as .\BuildTags.ps1 --input a --output b

If you set a breakpoint at line 36 and inspect $pathPairs, it looks normal. If you inspect the return value at line 39 or 40, however, it contains extra numbers, like this:

0
0
0
1
0
a
b
$ErrorActionPreference = "Stop"
function ParseArgs($inputArguments) {
$processingInput = $false
$processingOutput = $false
$inputPaths = [System.Collections.ArrayList]@()
$outputPaths = [System.Collections.ArrayList]@()
$inputArguments | ForEach-Object {
if ($_ -ieq "--inputs") {
$processingOutput = $false
$processingInput = $true
} elseif ($_ -ieq "--outputs") {
$processingOutput = $true
$processingInput = $false
} elseif ($processingInput -eq $true) {
$inputPaths.Add($_)
} elseif ($processingOutput -eq $true) {
$outputPaths.Add($_)
}
}
if (-not ($inputPaths.Count -eq $outputPaths.Count)) {
throw "Input and output path numbers mismatch"
exit 1
}
$pathPairs = [System.Collections.ArrayList]@()
for ($i = 0; $i -lt $inputPaths.Count; $i++) {
$entry = [System.Collections.ArrayList]@()
$entry.Add($inputPaths[$i])
$entry.Add($outputPaths[$i])
$pathPairs.Add($entry)
}
return $pathPairs
}
$abc = @(ParseArgs $args)
$pathPairs = ParseArgs $args
$gitHash = & git rev-parse HEAD
$gitBranch = & git rev-parse --abbrev-ref HEAD
$pathPairs | ForEach-Object {
Write-Host "Generating '$($_[1])'"
$inputFile = Get-Content -Path $_[0]
$outputFile = $inputFile.Replace("GitCommitHash = `"`"", "GitCommitHash = `"$($gitHash)`"").Replace("GitBranch = `"`"", "GitBranch = `"$($gitBranch)`"")
$outputFile | Set-Content -Path $_[1]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment