Allow automatic installer machine selection
Config Central CI Config Central passed all CI integrity checks.
Beffroi/config-central/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-10-17 09:53:32 +02:00
parent 4c38825b20
commit 05b45304a7
2 changed files with 30 additions and 3 deletions

View File

@ -1,8 +1,8 @@
#requires -Version 5.1
[CmdletBinding()]
param(
[ValidatePattern('^[a-z0-9][a-z0-9-]*$')][string]$Machine = $env:CONFIG_CENTRAL_MACHINE,
[ValidatePattern('^[A-Za-z0-9._/-]+$')][string]$Branch = $env:CONFIG_CENTRAL_BRANCH,
[string]$Machine = $env:CONFIG_CENTRAL_MACHINE,
[string]$Branch = $env:CONFIG_CENTRAL_BRANCH,
[switch]$SkipApply
)
@ -20,7 +20,15 @@ if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) {
if ([string]::IsNullOrWhiteSpace($env:TEMP) -or [string]::IsNullOrWhiteSpace($env:LOCALAPPDATA)) {
throw 'The interactive Windows user profile is unavailable.'
}
if ([string]::IsNullOrWhiteSpace($Branch)) { $Branch = 'main' }
if ([string]::IsNullOrWhiteSpace($Branch)) {
$Branch = 'main'
}
elseif ($Branch -notmatch '^[A-Za-z0-9._/-]+$') {
throw "Invalid branch name '$Branch'."
}
if (-not [string]::IsNullOrWhiteSpace($Machine) -and $Machine -notmatch '^[a-z0-9][a-z0-9-]*$') {
throw "Invalid machine name '$Machine'."
}
if ($env:CONFIG_CENTRAL_SKIP_APPLY -eq '1') { $SkipApply = $true }
function Get-SavedMachine {

View File

@ -39,4 +39,23 @@ Describe 'One-stop installer machine selection' {
Select-ConfigCentralMachine -Requested '' -Saved '' -Available @('example-desktop') |
Should -Be 'example-desktop'
}
It 'allows unset environment defaults through parameter binding' {
$previousMachine = $env:CONFIG_CENTRAL_MACHINE
$previousBranch = $env:CONFIG_CENTRAL_BRANCH
try {
$env:CONFIG_CENTRAL_MACHINE = $null
$env:CONFIG_CENTRAL_BRANCH = $null
$parameterProbe = [scriptblock]::Create(
$installerAst.ParamBlock.Extent.Text + "`n@{ Machine = `$Machine; Branch = `$Branch }"
)
$bound = & $parameterProbe
$bound.Machine | Should -BeNullOrEmpty
$bound.Branch | Should -BeNullOrEmpty
}
finally {
$env:CONFIG_CENTRAL_MACHINE = $previousMachine
$env:CONFIG_CENTRAL_BRANCH = $previousBranch
}
}
}