Skip to content

Commit f4abb8f

Browse files
committed
fix: update CHANGELOG and improve CLI help consistency
- Refactor CHANGELOG for clarity and formatting consistency - Enhance CLI help output to ensure consistent option spellings - Add tests for default console reader behavior in Invoke-NovaCliNativeConsoleReadKey
1 parent c12b905 commit f4abb8f

2 files changed

Lines changed: 27 additions & 39 deletions

File tree

src/private/cli/ConfirmNovaCliAction.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ function Invoke-NovaCliConsoleReadKey {
4444
function Invoke-NovaCliNativeConsoleReadKey {
4545
[CmdletBinding()] param([scriptblock]$Reader)
4646
if ($null -eq $Reader) {
47-
return [Console]::ReadKey($true)
47+
$Reader = Get-NovaCliNativeConsoleReadKeyReader
4848
}
4949

5050
return & $Reader
5151
}
5252

53+
function Get-NovaCliNativeConsoleReadKeyReader {
54+
[CmdletBinding()]
55+
param()
56+
57+
return {[Console]::ReadKey($true)}
58+
}
59+
5360
function Get-NovaCliConsoleReadKeyReader {
5461
[CmdletBinding()]
5562
param()

tests/CliHelperCoverage.Tests.ps1

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -147,46 +147,27 @@ Describe 'Targeted coverage for smaller CLI helper internals' {
147147
}
148148
}
149149

150-
It 'Invoke-NovaCliNativeConsoleReadKey uses the default console reader when no override is provided' {
151-
$runnerPath = Join-Path $TestDrive 'Invoke-NovaCliNativeConsoleReadKey.Runner.ps1'
152-
$stdinPath = Join-Path $TestDrive 'Invoke-NovaCliNativeConsoleReadKey.stdin.txt'
153-
$stdoutPath = Join-Path $TestDrive 'Invoke-NovaCliNativeConsoleReadKey.stdout.txt'
154-
$stderrPath = Join-Path $TestDrive 'Invoke-NovaCliNativeConsoleReadKey.stderr.txt'
155-
Set-Content -LiteralPath $stdinPath -Value '' -Encoding utf8 -NoNewline
156-
Set-Content -LiteralPath $runnerPath -Encoding utf8 -Value @"
157-
`$module = Import-Module '$script:distModuleDir' -Force -PassThru
158-
159-
try {
160-
& `$module {
161-
Invoke-NovaCliNativeConsoleReadKey | Out-Null
162-
}
150+
It 'Get-NovaCliNativeConsoleReadKeyReader exposes the native console read delegate' {
151+
InModuleScope $script:moduleName {
152+
$reader = Get-NovaCliNativeConsoleReadKeyReader
163153

164-
Write-Output 'NO_THROW'
165-
exit 1
166-
}
167-
catch {
168-
Write-Output `$_.FullyQualifiedErrorId
169-
Write-Output `$_.Exception.Message
170-
exit 0
171-
}
172-
"@
173-
174-
$process = Start-Process pwsh -ArgumentList @('-NoLogo', '-NoProfile', '-File', $runnerPath) `
175-
-RedirectStandardInput $stdinPath `
176-
-RedirectStandardOutput $stdoutPath `
177-
-RedirectStandardError $stderrPath `
178-
-Wait `
179-
-PassThru
180-
$output = @(
181-
if (Test-Path -LiteralPath $stdoutPath) {
182-
Get-Content -LiteralPath $stdoutPath
183-
}
184-
if (Test-Path -LiteralPath $stderrPath) {
185-
Get-Content -LiteralPath $stderrPath
154+
$reader | Should -BeOfType 'scriptblock'
155+
($reader.ToString()).Trim() | Should -Be '[Console]::ReadKey($true)'
186156
}
187-
)
157+
}
188158

189-
$process.ExitCode | Should -Be 0 -Because ($output -join [Environment]::NewLine)
190-
($output -join [Environment]::NewLine) | Should -Match 'Cannot read keys when either application does not have a console or when console input has been redirected'
159+
It 'Invoke-NovaCliNativeConsoleReadKey resolves the default native console reader when no override is provided' {
160+
InModuleScope $script:moduleName {
161+
Mock Get-NovaCliNativeConsoleReadKeyReader {
162+
{
163+
[pscustomobject]@{KeyChar = [char]'y'}
164+
}
165+
}
166+
167+
$result = Invoke-NovaCliNativeConsoleReadKey
168+
169+
$result.KeyChar | Should -Be ([char]'y')
170+
Assert-MockCalled Get-NovaCliNativeConsoleReadKeyReader -Times 1
171+
}
191172
}
192173
}

0 commit comments

Comments
 (0)