Private/Assert-InWatchmen.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
function Assert-InWatchmen {
    param ($Command)

    # Verify we aren't calling the command completly outside of a Watchmen file
    if ($null -eq $script:Watchmen) {
        throw "The command [$Command] may only be used inside a Watchmen configuration file."
    }

    # WatchmenOptions
    if ($script:Watchmen.InConfig) {
        if ($script:Watchmen.InNotifies) {
            if ($command -notin $script:CommandFences.Notifies) {
                throw "The Watchmen command [$Command] may only be used inside a Notifies block."
            }
        } else {
            if ($command -notin $script:CommandFences.WatchmenOptions) {
                throw "The Watchmen command [$Command] may only be used inside a WatchmenOptions block."
            }
        }
    }

    # WatchmenTest
    if ($script:WatchMen.InTest) {

        if ($script:Watchmen.InNotifies) {
            if ($command -notin $script:CommandFences.Notifies) {
                throw "The Watchmen command [$Command] may only be used inside a Notifies block."
            }
        } else {
            if ($command -notin $script:CommandFences.WatchmenTest) {
                throw "The Watchmen command [$Command] may only be used inside a WatchmenTest block."
            }
        }
    }

    # Notifies
    if ($script:WatchMen.InNotifies) {
        if ($command -notin $script:CommandFences.Notifies) {
            throw "The Watchmen command [$Command] may only be used inside a Notifies block."
        }
    }
}