Private/Test-PlatformSupport.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
function Test-PlatformSupport {
    [cmdletbinding()]
    param(
        $Type,
        [string[]]$Support
    )

    # test core/full
    if('Core' -eq $PSVersionTable.PSEdition) {
        if($Support -notcontains 'core') {
            Write-Verbose "Supported platforms [$Support] for type [$Type] does not contain [core]. Pull requests welcome!"
            return $false
        }
    }
    else { # full windows powershell
        if($Support -notcontains 'windows') {
            Write-Verbose "Supported platforms [$Support] for type [$Type] does not contain [windows]. Pull requests welcome!"
            return $false
        }
    }

    if($IsLinux) {
        if($Support -notcontains 'linux') {
            Write-Verbose "Supported platforms [$Support] for type [$Type] does not contain [linux]. Pull requests welcome!"
            return $false
        }
    }
    if($IsMacOS) {
        if($Support -notcontains 'macos') {
            Write-Verbose "Supported platforms [$Support] for type [$Type] does not contain [macos]. Pull requests welcome!"
            return $false
        }
    }
    if($IsWindows) {
        # covers support for core powershell on windows
        if($Support -notcontains 'windows') {
            Write-Verbose "Supported platforms [$Support] for type [$Type] does not contain [windows]. Pull requests welcome!"
            return $false
        }
    }
    $true
}