1
+ $Script :UseWriteHost = $true
2
+
3
+ if (! $Global :ColorScheme ) {
4
+ $Global :ColorScheme = @ {
5
+ " Banner" = [ConsoleColor ]::Cyan
6
+ " RuntimeName" = [ConsoleColor ]::Yellow
7
+ " Help_Header" = [ConsoleColor ]::Yellow
8
+ " Help_Switch" = [ConsoleColor ]::Green
9
+ " Help_Argument" = [ConsoleColor ]::Cyan
10
+ " Help_Optional" = [ConsoleColor ]::Gray
11
+ " Help_Command" = [ConsoleColor ]::DarkYellow
12
+ " Help_Executable" = [ConsoleColor ]::DarkYellow
13
+ " ParameterName" = [ConsoleColor ]::Cyan
14
+ " Warning" = [ConsoleColor ]::Yellow
15
+ }
16
+ }
17
+
18
+ function _WriteOut {
19
+ param (
20
+ [Parameter (Mandatory = $false , Position = 0 , ValueFromPipeline = $true )][string ]$msg ,
21
+ [Parameter (Mandatory = $false )][ConsoleColor ]$ForegroundColor ,
22
+ [Parameter (Mandatory = $false )][ConsoleColor ]$BackgroundColor ,
23
+ [Parameter (Mandatory = $false )][switch ]$NoNewLine )
24
+
25
+ if ($__TestWriteTo ) {
26
+ $cur = Get-Variable - Name $__TestWriteTo - ValueOnly - Scope Global - ErrorAction SilentlyContinue
27
+ $val = $cur + " $msg "
28
+ if (! $NoNewLine ) {
29
+ $val += [Environment ]::NewLine
30
+ }
31
+ Set-Variable - Name $__TestWriteTo - Value $val - Scope Global - Force
32
+ return
33
+ }
34
+
35
+ if (! $Script :UseWriteHost ) {
36
+ if (! $msg ) {
37
+ $msg = " "
38
+ }
39
+ if ($NoNewLine ) {
40
+ [Console ]::Write($msg )
41
+ } else {
42
+ [Console ]::WriteLine($msg )
43
+ }
44
+ }
45
+ else {
46
+ try {
47
+ if (! $ForegroundColor ) {
48
+ $ForegroundColor = $host.UI.RawUI.ForegroundColor
49
+ }
50
+ if (! $BackgroundColor ) {
51
+ $BackgroundColor = $host.UI.RawUI.BackgroundColor
52
+ }
53
+
54
+ Write-Host $msg - ForegroundColor:$ForegroundColor - BackgroundColor:$BackgroundColor - NoNewLine:$NoNewLine
55
+ } catch {
56
+ $Script :UseWriteHost = $false
57
+ _WriteOut $msg
58
+ }
59
+ }
60
+ }
61
+
62
+ function _WriteConfig {
63
+ param (
64
+ [Parameter (Mandatory = $true , Position = 0 )]$name ,
65
+ [Parameter (Mandatory = $true , Position = 1 )]$value )
66
+
67
+ _WriteOut - NoNewline - ForegroundColor $Global :ColorScheme.ParameterName " ${name} : "
68
+ _WriteOut " $value "
69
+
70
+ }
71
+
72
+ function _DownloadNuget {
73
+ param (
74
+ [Parameter (Mandatory = $true , Position = 0 )]$rootPath )
75
+
76
+ $sourceNugetExe = " http://nuget.org/nuget.exe"
77
+ $targetNugetExe = " $rootPath \nuget.exe"
78
+
79
+
80
+ if (! (Test-Path $targetNugetExe )){
81
+ _WriteOut " Downloading nuget to $targetNugetExe "
82
+ Invoke-WebRequest $sourceNugetExe - OutFile $targetNugetExe
83
+ }
84
+ else {
85
+ # _WriteOut "nuget.exe is already present"
86
+ }
87
+
88
+ Set-Alias nuget $targetNugetExe - Scope Global
89
+
90
+ }
0 commit comments