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
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:
parent
4c38825b20
commit
05b45304a7
14
install.ps1
14
install.ps1
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue