Skip to content

Commit

Permalink
Fix the problem with -1 in range (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
vors authored Jun 19, 2018
1 parent e5bf742 commit b6db4f9
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/platyPS/platyPS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,26 @@ function GetTypeString
return $TypeObjectHash.Name
}

<#
You cannot just write 0..($n-1) because if $n == 0 you are screwed.
Hence this helper.
#>
function GetRange
{
Param(
[CmdletBinding()]
[parameter(mandatory=$true)]
[int]$n
)
if ($n -lt 0) {
throw "GetRange $n is unsupported: value less then 0"
}
if ($n -eq 0) {
return
}
0..($n - 1)
}

<#
This function proxies Get-Command call.
Expand Down Expand Up @@ -2174,7 +2194,7 @@ function MyGetCommand
Write-Error $errStr
}

foreach ($i in 0..($parameters.Length - 1)) {
foreach ($i in (GetRange $parameters.Length)) {
$typeObjectHash = New-Object -TypeName pscustomobject -Property @{
Name = $parameterType[$i].Name
IsGenericType = $parameterType[$i].IsGenericType
Expand All @@ -2195,8 +2215,8 @@ function MyGetCommand

$psets = expand 'ParameterSets'
$psetsArray = @()
foreach ($i in 0..($psets.Count - 1)) {
$parameters = getParams $i $psets.Count
foreach ($i in (GetRange $psets.Count)) {
$parameters = getParams $i
$psetsArray += @(New-Object -TypeName pscustomobject -Property @{
Name = $psets[$i].Name
IsDefault = $psets[$i].IsDefault
Expand Down

0 comments on commit b6db4f9

Please sign in to comment.