Internal/Validate-VersionParameters.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

function Validate-VersionParameters {
    param (
        [Parameter()]
        [String[]]
        $Name,

        [Parameter()]
        [String]
        $MinimumVersion,

        [Parameter()]
        [String]
        $RequiredVersion,

        [Parameter()]
        [String]
        $MaximumVersion,

        [Parameter()]
        [Switch]
        $AllVersions
    )

    if ($AllVersions -and ($RequiredVersion -or $MinimumVersion -or $MaximumVersion)) {
        Throw-Error -ExceptionName "System.ArgumentException" `
                    -ExceptionMessage $LocalizedData.AllVersionsCannotBeUsedWithOtherVersionParameters `
                    -ErrorId 'AllVersionsCannotBeUsedWithOtherVersionParameters' `
                    -CallerPSCmdlet $PSCmdlet `
                    -ErrorCategory InvalidArgument
    }
    elseif ($RequiredVersion -and ($MinimumVersion -or $MaximumVersion)) {
        Throw-Error -ExceptionName "System.ArgumentException" `
                    -ExceptionMessage $LocalizedData.VersionRangeAndRequiredVersionCannotBeSpecifiedTogether `
                    -ErrorId "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether" `
                    -CallerPSCmdlet $PSCmdlet `
                    -ErrorCategory InvalidArgument
    }
    elseif ($MinimumVersion -and $MaximumVersion -and ($MinimumVersion -gt $MaximumVersion)) {
        $Message = $LocalizedData.MinimumVersionIsGreaterThanMaximumVersion -f ($MinimumVersion, $MaximumVersion)
        Throw-Error -ExceptionName "System.ArgumentException" `
                    -ExceptionMessage $Message `
                    -ErrorId "MinimumVersionIsGreaterThanMaximumVersion" `
                    -CallerPSCmdlet $PSCmdlet `
                    -ErrorCategory InvalidArgument
    }
    elseif ($AllVersions -or $RequiredVersion -or $MinimumVersion -or $MaximumVersion) {
        #if (-not $Name -or $Name.Count -ne 1 -or ([System.Management.Automation.WildcardPattern]::ContainsWildcardCharacters($Name[0]))) {
        # Throw-Error -ExceptionName "System.ArgumentException" `
        # -ExceptionMessage $LocalizedData.VersionParametersAreAllowedOnlyWithSingleName `
        # -ErrorId "VersionParametersAreAllowedOnlyWithSingleName" `
        # -CallerPSCmdlet $PSCmdlet `
        # -ErrorCategory InvalidArgument
        #}
    }

    return $true
}