Skip to content

Commit 0063744

Browse files
committed
Enforce Language parameter with InstallLanguagePack
Added validation to require the -Language parameter when -InstallLanguagePack is specified in Install-Defaults.ps1. Updated Install-deDE.ps1 to use -InstallLanguagePack and added a test to verify the new validation logic.
1 parent 3455d18 commit 0063744

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/Install-Defaults.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ param (
4545
[System.Globalization.CultureInfo] $Language, # Set the specified locale / language
4646

4747
[Parameter(Mandatory = $false)]
48+
[ValidateScript({
49+
if ($_ -and -not $PSBoundParameters.ContainsKey('Language')) {
50+
throw "The -Language parameter is required when -InstallLanguagePack is specified."
51+
}
52+
return $true
53+
})]
4854
[System.Management.Automation.SwitchParameter] $InstallLanguagePack, # Install the language pack for the specified language
4955

5056
[Parameter(Mandatory = $false)]

src/Install-deDE.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ if (!([System.Environment]::Is64BitProcess)) {
3636
#endregion
3737

3838
Set-Location -Path $PSScriptRoot
39-
& "$PSScriptRoot\Install-Defaults.ps1" -Language "de-DE" -TimeZone "Georgian Standard Time"
39+
& "$PSScriptRoot\Install-Defaults.ps1" -Language "de-DE" -InstallLanguagePack -TimeZone "Georgian Standard Time"

tests/Install-Defaults.Tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ Describe 'Install-Defaults.ps1 Script Execution' -Skip:(-not $IsAdmin) {
113113
}
114114

115115
Describe 'Install-Defaults.ps1 Language Support' -Skip:(-not $IsAdmin) {
116+
It 'Should require Language parameter when InstallLanguagePack is specified' {
117+
Push-Location -Path $([System.IO.Path]::Combine($Path, "src"))
118+
$params = @{
119+
Path = $([System.IO.Path]::Combine($Path, "src"))
120+
InstallLanguagePack = $true
121+
WhatIf = $true
122+
}
123+
{ & $ScriptPath.FullName @params } | Should -Throw -ExpectedMessage "The -Language parameter is required when -InstallLanguagePack is specified."
124+
Pop-Location
125+
}
126+
116127
It 'Should install language pack only on supported OS' {
117128
if ($OSInfo.SupportsLanguagePack) {
118129
Push-Location -Path $([System.IO.Path]::Combine($Path, "src"))

0 commit comments

Comments
 (0)