-
Notifications
You must be signed in to change notification settings - Fork 4
/
FormatTaskName.ps1
95 lines (76 loc) · 2.26 KB
/
FormatTaskName.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
function FormatTaskName {
<#
.SYNOPSIS
This function allows you to change how psake renders the task name during a build.
.DESCRIPTION
This function takes either a string which represents a format string (formats using the -f format operator see "help about_operators") or it can accept a script block that has a single parameter that is the name of the task that will be executed.
.PARAMETER format
A format string or a scriptblock to execute
.EXAMPLE
A sample build script that uses a format string is shown below:
Task default -depends TaskA, TaskB, TaskC
FormatTaskName "-------- {0} --------"
Task TaskA {
"TaskA is executing"
}
Task TaskB {
"TaskB is executing"
}
Task TaskC {
"TaskC is executing"
-----------
The script above produces the following output:
-------- TaskA --------
TaskA is executing
-------- TaskB --------
TaskB is executing
-------- TaskC --------
TaskC is executing
Build Succeeded!
.EXAMPLE
A sample build script that uses a ScriptBlock is shown below:
Task default -depends TaskA, TaskB, TaskC
FormatTaskName {
param($taskName)
write-host "Executing Task: $taskName" -foregroundcolor blue
}
Task TaskA {
"TaskA is executing"
}
Task TaskB {
"TaskB is executing"
}
Task TaskC {
"TaskC is executing"
}
-----------
The above example uses the scriptblock parameter to the FormatTaskName function to render each task name in the color blue.
Note: the $taskName parameter is arbitrary, it could be named anything.
.LINK
Assert
.LINK
Exec
.LINK
Framework
.LINK
Get-PSakeScriptTasks
.LINK
Include
.LINK
Invoke-psake
.LINK
Properties
.LINK
Task
.LINK
TaskSetup
.LINK
TaskTearDown
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
$format
)
$psake.context.Peek().config.taskNameFormat = $format
}