Skip to content

Commit 1b216b4

Browse files
committed
feat(#146): enhance Nova CLI bump command with warning message handling
- Implemented Invoke-NovaCliBumpCommand to manage version bump warnings - Added Write-NovaCliCapturedWarning and Get-NovaCliReplayWarningMessage functions for warning message processing - Updated tests to verify major-zero advisory message formatting
1 parent 293b46f commit 1b216b4

4 files changed

Lines changed: 77 additions & 5 deletions

File tree

src/private/cli/InvokeNovaCliCommandRoute.ps1

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,62 @@ function Invoke-NovaCliParsedCommand {
3939
return & $ActionCommand @options @mutatingCommonParameters
4040
}
4141

42+
function Invoke-NovaCliBumpCommand {
43+
[CmdletBinding()]
44+
param(
45+
[Parameter(Mandatory)][pscustomobject]$InvocationContext
46+
)
47+
48+
$warningMessages = @()
49+
$result = Invoke-NovaCliParsedCommand -InvocationContext $InvocationContext -ParserCommand 'ConvertFrom-NovaBumpCliArgument' -ActionCommand 'Update-NovaModuleVersion' -WarningAction SilentlyContinue -WarningVariable warningMessages
50+
Write-NovaCliCapturedWarning -WarningMessages $warningMessages -SkippedMessage (Get-NovaCliVersionUpdateAdvisoryMessage -Result $result)
51+
return $result
52+
}
53+
54+
function Write-NovaCliCapturedWarning {
55+
[CmdletBinding()]
56+
param(
57+
[object[]]$WarningMessages = @(),
58+
[string]$SkippedMessage
59+
)
60+
61+
foreach ($message in (Get-NovaCliReplayWarningMessage -WarningMessages $WarningMessages -SkippedMessage $SkippedMessage)) {
62+
Write-Warning $message
63+
}
64+
}
65+
66+
function Get-NovaCliReplayWarningMessage {
67+
[CmdletBinding()]
68+
param(
69+
[object[]]$WarningMessages = @(),
70+
[string]$SkippedMessage
71+
)
72+
73+
$messages = foreach ($warningMessage in @($WarningMessages)) {
74+
$text = ConvertTo-NovaCliWarningMessageText -WarningMessage $warningMessage
75+
if ([string]::IsNullOrWhiteSpace($text) -or $text -eq $SkippedMessage) {
76+
continue
77+
}
78+
79+
$text
80+
}
81+
82+
return @($messages)
83+
}
84+
85+
function ConvertTo-NovaCliWarningMessageText {
86+
[CmdletBinding()]
87+
param(
88+
[Parameter(Mandatory)][object]$WarningMessage
89+
)
90+
91+
if ($WarningMessage -is [System.Management.Automation.WarningRecord]) {
92+
return $WarningMessage.Message
93+
}
94+
95+
return [string]$WarningMessage
96+
}
97+
4298
function Invoke-NovaCliUpdateRouteCommand {
4399
[CmdletBinding()]
44100
param(
@@ -55,7 +111,7 @@ function Invoke-NovaCliBumpRouteCommand {
55111
[Parameter(Mandatory)][pscustomobject]$InvocationContext
56112
)
57113

58-
$result = Invoke-NovaCliParsedCommand -InvocationContext $InvocationContext -ParserCommand 'ConvertFrom-NovaBumpCliArgument' -ActionCommand 'Update-NovaModuleVersion'
114+
$result = Invoke-NovaCliBumpCommand -InvocationContext $InvocationContext
59115
return Format-NovaCliCommandResult -Command $InvocationContext.Command -Result $result
60116
}
61117

tests/NovaCommandModel.BumpAndCli.Tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,21 @@ Describe 'Nova command model - bump and CLI confirmation behavior' {
707707
}
708708
}
709709

710+
It 'Invoke-NovaCli bump formats the major-zero advisory once when the routed bump command returns the same advisory warning' {
711+
InModuleScope $script:moduleName {
712+
$advisoryMessage = 'Major version zero (0.y.z) is for initial development.'
713+
Mock Update-NovaModuleVersion {
714+
Write-Warning $advisoryMessage
715+
[pscustomobject]@{PreviousVersion = '0.1.0'; NewVersion = '0.2.0'; Label = 'Major'; EffectiveLabel = 'Minor'; AdvisoryMessage = $advisoryMessage; CommitCount = 1; Applied = $false}
716+
}
717+
718+
$result = Invoke-NovaCli bump -WhatIf
719+
720+
$result | Should -Be "Version plan: 0.1.0 -> 0.2.0 | Label: Major | Commits: 1$( [Environment]::NewLine )$advisoryMessage"
721+
([regex]::Matches($result,[regex]::Escape($advisoryMessage))).Count | Should -Be 1
722+
}
723+
}
724+
710725
It 'Confirm-NovaCliCommandAction accepts Enter as the default confirmation response' {
711726
Invoke-ConfirmNovaCliCommandActionEnterAssertion -ModuleName $script:moduleName
712727
}

tests/NovaCommandModel.StandaloneCli.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ Describe '$projectName tests' {
343343
$bumpResult.Text | Should -Match 'Version plan: 0\.1\.0 -> 0\.2\.0 \| Label: Major \| Commits: 1'
344344
$bumpResult.Text | Should -Match 'Major version zero \(0\.y\.z\) is for initial development'
345345
$bumpResult.Text | Should -Match 'Set 1\.0\.0 manually once the software is stable'
346+
([regex]::Matches($bumpResult.Text, 'Major version zero \(0\.y\.z\) is for initial development')).Count | Should -Be 1
346347
$bumpResult.Text | Should -Not -Match 'Version bumped to :'
347348
$versionAfterBump | Should -Be '0.1.0'
348349
}

tests/UpdateNotification.Tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ Continue with the prerelease update?
825825
$result.Warnings[0] | Should -Match 'newer NovaModuleTools release is available'
826826
$result.Warnings[0] | Should -Match 'Release notes: https://www\.novamoduletools\.com/release-notes\.html'
827827
$result.Warnings[0] | Should -Match 'Update-Module NovaModuleTools'
828-
$result.Warnings[0] | Should -Match 'nova update'
828+
$result.Warnings[0] | Should -Match '% nova update'
829829
}
830830

831831
It 'Invoke-NovaBuildUpdateNotification warns about a newer prerelease only when prerelease notifications are enabled' {
@@ -838,9 +838,9 @@ Continue with the prerelease update?
838838
$result.Warnings[0] | Should -Match 'newer NovaModuleTools prerelease is available'
839839
$result.Warnings[0] | Should -Match 'Release notes: https://www\.novamoduletools\.com/release-notes\.html'
840840
$result.Warnings[0] | Should -Match 'Update-Module NovaModuleTools -AllowPrerelease'
841-
$result.Warnings[0] | Should -Match 'nova update'
841+
$result.Warnings[0] | Should -Match '% nova update'
842842
$result.Warnings[0] | Should -Match 'Set-NovaUpdateNotificationPreference -DisablePrereleaseNotifications'
843-
$result.Warnings[0] | Should -Match 'nova notification --disable'
843+
$result.Warnings[0] | Should -Match '% nova notification --disable'
844844
}
845845

846846
It 'Write-NovaAvailableModuleUpdateWarning preserves host rendering so warning text can stay colored' {
@@ -873,7 +873,7 @@ Continue with the prerelease update?
873873
''
874874
'Update:'
875875
'PS> Update-Module NovaModuleTools'
876-
'nova update'
876+
'% nova update'
877877
)
878878
}
879879
}

0 commit comments

Comments
 (0)