utils/ConsoleUtils.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<#
.Synopsis
    Utility function to Show differnt Type of Information to the console
.DESCRIPTION
   This function takes the cluster DNS name and type and fetches the relevant Hadoop configs
    
.EXAMPLE
    ## To be added.
     
.LINK
    https://github.com/mabushaireh/HDICloner
#>



Function Get-Stack {
    $stack = ""
    $Global:Var = (Get-PSCallStack).Command

    For ($Index = 2; $Index -lt $Var.Length-1; $Index++) {
        $stack = $stack + "$($Var[$Index])" + ":"
    }

    return $stack
}
 
function Show-Prompt ($msg)
{
    $timeStamp = Get-TimeStampUtc
    $stack = Get-Stack
    $errorMsg = "$timeStamp : INFO - $stack - $Msg"    
    # save the current color
    $fc = $host.UI.RawUI.ForegroundColor

     # set the new color
     $host.UI.RawUI.ForegroundColor = "Green"

     Write-Host $errorMsg
     
     # restore the original color
     $host.UI.RawUI.ForegroundColor = $fc
}
function Show-Error($Msg)
{
    $timeStamp = Get-TimeStampUtc
    $stack = Get-Stack
    $errorMsg = "$timeStamp : ERROR - $stack - $Msg"    
    # save the current color
    $fc = $host.UI.RawUI.ForegroundColor

    # set the new color
    $host.UI.RawUI.ForegroundColor = "Red"

    Write-Host $errorMsg
    
    # restore the original color
    $host.UI.RawUI.ForegroundColor = $fc
}

function Show-Warning($Msg)
{
    $timeStamp = Get-TimeStampUtc
    $stack = Get-Stack
    $errorMsg = "$timeStamp : WARN - $stack - $Msg"    # save the current color
    $fc = $host.UI.RawUI.ForegroundColor

    # set the new color
    $host.UI.RawUI.ForegroundColor = "Yellow"

    Write-Host $errorMsg
    
    # restore the original color
    $host.UI.RawUI.ForegroundColor = $fc
}

function Show-Info($Msg)
{
    $timeStamp = Get-TimeStampUtc
    $stack = Get-Stack
    $errorMsg = "$timeStamp : INFO - $stack - $Msg"
    # save the current color
    $fc = $host.UI.RawUI.ForegroundColor

    # set the new color
    $host.UI.RawUI.ForegroundColor = "White"

    Write-Host $errorMsg
    
    # restore the original color
    $host.UI.RawUI.ForegroundColor = $fc
}



function Show-Debug($Msg)
{
    if ($global:IsDebug -eq $false){
        return
    }

    $timeStamp = Get-TimeStampUtc
    $stack = Get-Stack
    $errorMsg = "$timeStamp : DEBUG - $stack - $Msg"
    # save the current color
    $fc = $host.UI.RawUI.ForegroundColor

    # set the new color
    $host.UI.RawUI.ForegroundColor = "Cyan"

    Write-Host $errorMsg
    
    # restore the original color
    $host.UI.RawUI.ForegroundColor = $fc
}