2020-10-02 16:45:04 +00:00
|
|
|
class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator {
|
2020-11-05 05:00:18 +00:00
|
|
|
hidden static [hashtable]$_HardCodedConfigDict = @{
|
2020-11-25 05:46:33 +00:00
|
|
|
'myconfig' = @($(Join-Path $(Join-Path $PackagePath 'src') 'config.files.json'),
|
|
|
|
$(Join-Path $(Join-Path $PackagePath 'src') 'config.files.local.json'))
|
|
|
|
'mymodules' = @($(Join-Path $(Join-Path $PackagePath 'src') 'modules.json'),
|
|
|
|
$(Join-Path $(Join-Path $PackagePath 'src') 'modules.local.json'))
|
2020-11-05 05:00:18 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 04:31:34 +00:00
|
|
|
static [hashtable]GetConfigDictionary() {
|
|
|
|
$local:result = @{}
|
2020-11-05 05:00:18 +00:00
|
|
|
[MyConfig]::_HardCodedConfigDict.Keys | ForEach-Object { $result[$_] = [MyConfig]::_HardCodedConfigDict[$_] }
|
|
|
|
foreach( $local:jsonSource in $result.myconfig ) {
|
2020-11-05 04:31:34 +00:00
|
|
|
if( -not ( Test-Path $jsonSource ) ) { continue }
|
|
|
|
foreach( $local:prop in $(Get-Content $jsonSource | ConvertFrom-Json).PSObject.Properties ) {
|
|
|
|
$result[$prop.Name] = $prop.Value
|
|
|
|
}
|
2020-10-31 21:10:32 +00:00
|
|
|
}
|
2020-11-05 04:31:34 +00:00
|
|
|
return $result;
|
2020-10-02 16:45:04 +00:00
|
|
|
}
|
2020-10-31 21:10:32 +00:00
|
|
|
static [string[]] GetConfigPaths([string[]]$ConfigNames,[switch]$Force) {
|
2020-11-05 04:31:34 +00:00
|
|
|
$local:configDirectory = [MyConfig]::GetConfigDictionary()
|
2020-10-31 21:10:32 +00:00
|
|
|
$local:result = [string[]]@()
|
|
|
|
$local:flat = $false
|
|
|
|
while(-not $flat) {
|
|
|
|
$flat = $true
|
|
|
|
$ConfigNames += $ConfigNames | ForEach-Object {
|
2020-11-05 04:31:34 +00:00
|
|
|
$configDirectory[$_]
|
2020-10-31 21:10:32 +00:00
|
|
|
} | Where-Object { $_ -match '^#[\w-\.]+$' } | ForEach-Object {
|
|
|
|
$_.Substring(1)
|
|
|
|
} | Where-Object { $_ -notin $ConfigNames } | ForEach-Object {
|
|
|
|
$flat = false; $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$local:flatConfigList = $ConfigNames | ForEach-Object {
|
2020-11-05 04:31:34 +00:00
|
|
|
$configDirectory[$_]
|
2020-10-31 21:10:32 +00:00
|
|
|
} | Where-Object { $_ -notmatch '^#[\w-\.]+$' }
|
|
|
|
|
|
|
|
$local:exists = $false;
|
|
|
|
$local:first = $null
|
|
|
|
foreach( $local:configPath in $flatConfigList ) {
|
2020-12-02 04:31:42 +00:00
|
|
|
$configPath = Get-Path $configPath
|
2020-10-31 21:10:32 +00:00
|
|
|
if( -not $first ) { $first = $configPath }
|
|
|
|
if( $Force -or (Test-Path $configPath) ) {
|
2020-12-02 04:31:42 +00:00
|
|
|
$result += $configPath
|
2020-10-31 21:10:32 +00:00
|
|
|
$exists = $true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( -not $exists -and -not $Force ) {
|
|
|
|
$result += $first
|
|
|
|
}
|
|
|
|
return $result
|
2020-10-02 16:45:04 +00:00
|
|
|
}
|
|
|
|
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
|
2020-11-05 04:31:34 +00:00
|
|
|
$local:possibleValues = [MyConfig]::GetConfigDictionary().Keys
|
2020-10-02 16:45:04 +00:00
|
|
|
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
|
|
|
|
}
|
|
|
|
|
|
|
|
[String[]] GetValidValues() {
|
|
|
|
return [MyConfig]::_GetValidValues('',$true)
|
|
|
|
}
|
|
|
|
}
|