Classes/ParcelStatus.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
class ParcelStatus
{
    [ParcelStatusType] $Status
    [string] $Reason = [string]::Empty

    ParcelStatus([ParcelStatusType]$_status)
    {
        $this.Status = $_status
    }

    ParcelStatus([ParcelStatusType]$_status, [string]$_reason)
    {
        $this.Status = $_status
        $this.Reason = $_reason
    }

    [void] WriteStatusMessage([bool]$_dryRun)
    {
        if ($_dryRun) {
            Write-Host '[WhatIf]: ' -ForegroundColor Cyan -NoNewline
        }

        switch ($this.Status) {
            'Skipped' {
                Write-Host $this.Status -ForegroundColor Green -NoNewline
            }

            'Changed' {
                Write-Host $this.Status -ForegroundColor Yellow -NoNewline
            }
        }

        if ([string]::IsNullOrWhiteSpace($this.Reason)) {
            Write-Host ([string]::Empty)
        }
        else {
            Write-Host " (reason: $($this.Reason.ToLowerInvariant()))"
        }
    }
}