Skip to content

Commit f9e7f8a

Browse files
committed
#151 feat: default prerelease self-update confirmation to no
1 parent 5d7cc93 commit f9e7f8a

9 files changed

Lines changed: 49 additions & 25 deletions

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Changed
1414

15+
- Make prerelease self-update confirmation default to `No`.
16+
- `Update-NovaModuleTool`, `Update-NovaModuleTools`, and `% nova update` now require an explicit `Y` before a
17+
prerelease self-update continues, so pressing Enter cancels the update instead of accepting it.
18+
1519
### Deprecated
1620

1721
### Removed
@@ -358,4 +362,3 @@ Keep stable `Update-NovaModuleVersion` / `% nova bump` releases on the SemVer ma
358362
[0.0.6]: https://github.com/stiwicourage/NovaModuleTools/compare/Version_0.0.5...Version_0.0.6
359363
[0.0.5]: https://github.com/stiwicourage/NovaModuleTools/compare/Version_0.0.4...Version_0.0.5
360364
[0.0.4]: https://github.com/stiwicourage/NovaModuleTools/compare/Version_0.0.3...Version_0.0.4
361-

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ Update notification preferences use one shared settings location:
110110
`Update-NovaModuleTool` (and its `Update-NovaModuleTools` alias), CLI:`% nova update` use that stored prerelease
111111
preference to decide whether prerelease self-updates are eligible. When prerelease self-updates are disabled,
112112
self-update stays on stable releases. When they are enabled, self-update may target a prerelease, but it asks for
113-
explicit confirmation before proceeding.
113+
explicit confirmation before proceeding and defaults that prerelease prompt to `No`, so pressing Enter cancels the
114+
update.
114115

115116

116117
Successful `Update-NovaModuleTool`, CLI:`% nova update`, and `Install-NovaCli` runs print the release notes link from

docs/NovaModuleTools/en-US/Get-NovaUpdateNotificationPreference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ eligible.
8181
Use `Set-NovaUpdateNotificationPreference -EnablePrereleaseNotifications` to allow prerelease self-updates again.
8282

8383
When prerelease notifications are enabled again, `Update-NovaModuleTool` / `Update-NovaModuleTools` may again select a
84-
prerelease target. Prerelease self-updates still require explicit confirmation before the update proceeds.
84+
prerelease target. Prerelease self-updates still require explicit confirmation before the update proceeds, and that
85+
confirmation defaults to `No` so pressing Enter cancels the update.
8586

8687
## RELATED LINKS
8788

docs/NovaModuleTools/en-US/NovaModuleTools.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ Runs the project's Pester test workflow using settings from `project.json`.
6262
### `PS> Update-NovaModuleTool`
6363

6464
Updates the installed `NovaModuleTools` module by using the stored prerelease preference that also controls whether
65-
prerelease self-updates are eligible. The compatibility alias `Update-NovaModuleTools` is also available.
65+
prerelease self-updates are eligible. Prerelease confirmations default to `No`, so pressing Enter cancels the
66+
update. The compatibility alias `Update-NovaModuleTools` is also available.
6667

6768
### `PS> Initialize-NovaModule`
6869

docs/NovaModuleTools/en-US/Update-NovaModuleTools.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ When prerelease notifications are disabled, `Update-NovaModuleTool` only conside
3737
`-AllowPrerelease` to the update flow.
3838

3939
When prerelease notifications are enabled, `Update-NovaModuleTool` may target a prerelease. If the selected target is a
40-
prerelease, the command always asks for explicit confirmation before it proceeds.
40+
prerelease, the command always asks for explicit confirmation before it proceeds, and that prerelease confirmation
41+
defaults to `No` so pressing Enter cancels the update.
4142

4243
Stable updates do not require prerelease confirmation.
4344

docs/versioning-and-updates.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ <h3>What self-update does</h3>
281281
<tr>
282282
<td>Only prerelease update available and prerelease eligibility is enabled</td>
283283
<td>Nova may target the prerelease, but it always asks for explicit confirmation before
284-
updating.
284+
updating, and that prompt defaults to No so pressing Enter cancels the update.
285285
</td>
286286
</tr>
287287
<tr>

src/private/update/ConfirmNovaPrereleaseModuleUpdate.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ function Confirm-NovaPrereleaseModuleUpdate {
77
)
88

99
$prompt = Get-NovaPrereleaseModuleUpdateConfirmationPrompt -CurrentVersion $CurrentVersion -TargetVersion $TargetVersion
10-
return $Cmdlet.ShouldContinue($prompt.Message, $prompt.Caption)
10+
return (Read-AwesomeChoicePrompt -Ask $prompt -HostUi $Cmdlet.Host.UI) -eq 'Y'
1111
}

src/private/update/GetNovaPrereleaseModuleUpdateConfirmationPrompt.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@ NovaModuleTools would update from $CurrentVersion to prerelease $TargetVersion.
1313
Prerelease updates may be less stable than released versions.
1414
Continue with the prerelease update?
1515
"@
16+
Choice = [ordered]@{
17+
Y = 'Yes'
18+
N = 'No'
19+
}
20+
Default = 'N'
1621
}
1722
}

tests/UpdateNotification.Tests.ps1

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -732,33 +732,45 @@ NovaModuleTools would update from 1.2.3 to prerelease 1.3.0-preview1.
732732
Prerelease updates may be less stable than released versions.
733733
Continue with the prerelease update?
734734
"@
735+
$prompt.Choice.Keys | Should -Be @('Y', 'N')
736+
$prompt.Default | Should -Be 'N'
735737
}
736738
}
737739

738-
It 'Confirm-NovaPrereleaseModuleUpdate delegates the generated prompt to ShouldContinue and returns the decision' {
739-
InModuleScope $script:moduleName {
740-
$calls = [System.Collections.Generic.List[object]]::new()
741-
$cmdlet = [pscustomobject]@{
742-
Calls = $calls
743-
ShouldContinueResult = $false
740+
It 'Confirm-NovaPrereleaseModuleUpdate uses a choice prompt that defaults prerelease updates to No' -ForEach @(
741+
@{ChoiceIndex = 1; Expected = $false}
742+
@{ChoiceIndex = 0; Expected = $true}
743+
) {
744+
InModuleScope $script:moduleName -Parameters @{TestCase = $_} {
745+
param($TestCase)
746+
747+
$hostUi = [pscustomobject]@{
748+
State = [ordered]@{
749+
ChoiceCalls = 0
750+
ChoiceLabels = @()
751+
DefaultChoiceIndex = $null
752+
}
744753
}
745-
$cmdlet | Add-Member -MemberType ScriptMethod -Name ShouldContinue -Value {
746-
param($Message, $Caption)
754+
$hostUi | Add-Member -MemberType ScriptMethod -Name PromptForChoice -Value {
755+
param($Caption, $Message, $Choices, $DefaultChoiceIndex)
747756

748-
$this.Calls.Add([pscustomobject]@{
749-
Message = $Message
750-
Caption = $Caption
751-
}) | Out-Null
752-
return $this.ShouldContinueResult
757+
$this.State.ChoiceCalls += 1
758+
$this.State.ChoiceLabels = @($Choices | ForEach-Object Label)
759+
$this.State.DefaultChoiceIndex = $DefaultChoiceIndex
760+
return $TestCase.ChoiceIndex
761+
}
762+
$cmdlet = [pscustomobject]@{
763+
Host = [pscustomobject]@{
764+
UI = $hostUi
765+
}
753766
}
754767

755768
$result = Confirm-NovaPrereleaseModuleUpdate -Cmdlet $cmdlet -CurrentVersion '1.2.3' -TargetVersion '2.0.0-preview2'
756769

757-
$result | Should -BeFalse
758-
$calls.Count | Should -Be 1
759-
$calls[0].Caption | Should -Be 'Confirm prerelease NovaModuleTools update'
760-
$calls[0].Message | Should -Match '1.2.3'
761-
$calls[0].Message | Should -Match '2.0.0-preview2'
770+
$result | Should -Be $TestCase.Expected
771+
$hostUi.State.ChoiceCalls | Should -Be 1
772+
$hostUi.State.ChoiceLabels | Should -Be @('&Y', '&N')
773+
$hostUi.State.DefaultChoiceIndex | Should -Be 1
762774
}
763775
}
764776

0 commit comments

Comments
 (0)