-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatNovaCliCommandResult.ps1
More file actions
73 lines (59 loc) · 1.83 KB
/
Copy pathFormatNovaCliCommandResult.ps1
File metadata and controls
73 lines (59 loc) · 1.83 KB
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
function Test-NovaCliNoUpdateResult {
[CmdletBinding()]
param(
[string]$Command,
[object]$Result
)
if ($Command -ne 'update' -or $null -eq $Result) {
return $false
}
$propertyNames = @($Result.PSObject.Properties.Name)
return ($propertyNames -contains 'UpdateAvailable') -and ($propertyNames -contains 'CurrentVersion') -and -not $Result.UpdateAvailable
}
function Test-NovaCliVersionUpdateResult {
[CmdletBinding()]
param(
[string]$Command,
[object]$Result
)
if ($Command -ne 'bump' -or $null -eq $Result) {
return $false
}
$propertyNames = @($Result.PSObject.Properties.Name)
foreach ($requiredPropertyName in @('PreviousVersion', 'NewVersion', 'Label', 'CommitCount', 'Applied')) {
if ($propertyNames -notcontains $requiredPropertyName) {
return $false
}
}
return $true
}
function Format-NovaCliVersionUpdateResult {
[CmdletBinding()]
param(
[Parameter(Mandatory)][object]$Result
)
$summaryPrefix = if ($Result.Applied) {
'Version bump completed:'
}
else {
'Version plan:'
}
return "$summaryPrefix $( $Result.PreviousVersion ) -> $( $Result.NewVersion ) | Label: $( $Result.Label ) | Commits: $( $Result.CommitCount )"
}
function Format-NovaCliCommandResult {
[CmdletBinding()]
param(
[string]$Command,
[object]$Result
)
if (Test-NovaCliNoUpdateResult -Command $Command -Result $Result) {
return @(
"You're up to date!"
"$( $Result.ModuleName ) $( $Result.CurrentVersion ) is currently the newest version available."
)
}
if (Test-NovaCliVersionUpdateResult -Command $Command -Result $Result) {
return Format-NovaCliVersionUpdateResult -Result $Result
}
return $Result
}