Introducing Packages
Major Overhaul with Breaking Changes split into packaged, default behavior moved into 'base' package each package has a json package description file with criteria for loading Modified Setup-Profile to refer to 'base' package path for auto loading moved Linux aliases and command to 'base.linux' package created 'docker' package to address docker supported systems modified Get-MyScripts, Edit-MyScripts and Reload-MyScripts accordingly. Dropped -System and sys.*, package json conditions will take care of it. Supplied command to create/edit package json files: - New-MyPackage - Add-PackageCondition - Set-MyPackage
This commit is contained in:
parent
80a488484b
commit
42b39f4e25
83 changed files with 505 additions and 130 deletions
61
base/profile.d/MyConfig.class.ps1
Normal file
61
base/profile.d/MyConfig.class.ps1
Normal file
|
@ -0,0 +1,61 @@
|
|||
class MyConfig { #: System.Management.Automation.IValidateSetValuesGenerator {
|
||||
hidden static [hashtable]$_HardCodedConfigDict = @{
|
||||
'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'))
|
||||
}
|
||||
|
||||
static [hashtable]GetConfigDictionary() {
|
||||
$local:result = @{}
|
||||
[MyConfig]::_HardCodedConfigDict.Keys | ForEach-Object { $result[$_] = [MyConfig]::_HardCodedConfigDict[$_] }
|
||||
foreach( $local:jsonSource in $result.myconfig ) {
|
||||
if( -not ( Test-Path $jsonSource ) ) { continue }
|
||||
foreach( $local:prop in $(Get-Content $jsonSource | ConvertFrom-Json).PSObject.Properties ) {
|
||||
$result[$prop.Name] = $prop.Value
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
static [string[]] GetConfigPaths([string[]]$ConfigNames,[switch]$Force) {
|
||||
$local:configDirectory = [MyConfig]::GetConfigDictionary()
|
||||
$local:result = [string[]]@()
|
||||
$local:flat = $false
|
||||
while(-not $flat) {
|
||||
$flat = $true
|
||||
$ConfigNames += $ConfigNames | ForEach-Object {
|
||||
$configDirectory[$_]
|
||||
} | Where-Object { $_ -match '^#[\w-\.]+$' } | ForEach-Object {
|
||||
$_.Substring(1)
|
||||
} | Where-Object { $_ -notin $ConfigNames } | ForEach-Object {
|
||||
$flat = false; $_;
|
||||
}
|
||||
}
|
||||
|
||||
$local:flatConfigList = $ConfigNames | ForEach-Object {
|
||||
$configDirectory[$_]
|
||||
} | Where-Object { $_ -notmatch '^#[\w-\.]+$' }
|
||||
|
||||
$local:exists = $false;
|
||||
$local:first = $null
|
||||
foreach( $local:configPath in $flatConfigList ) {
|
||||
if( -not $first ) { $first = $configPath }
|
||||
if( $Force -or (Test-Path $configPath) ) {
|
||||
$result += Get-Path $configPath
|
||||
$exists = $true
|
||||
}
|
||||
}
|
||||
if( -not $exists -and -not $Force ) {
|
||||
$result += $first
|
||||
}
|
||||
return $result
|
||||
}
|
||||
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
|
||||
$local:possibleValues = [MyConfig]::GetConfigDictionary().Keys
|
||||
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
|
||||
}
|
||||
|
||||
[String[]] GetValidValues() {
|
||||
return [MyConfig]::_GetValidValues('',$true)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue