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
|
@ -1,83 +0,0 @@
|
|||
[CmdletBinding(SupportsShouldProcess)]param(
|
||||
[ArgumentCompleter({ param (
|
||||
$commandName,
|
||||
$parameterName,
|
||||
$wordToComplete,
|
||||
$commandAst,
|
||||
$fakeBoundParameters
|
||||
)
|
||||
[FunctionName]::_GetValidValues($wordToComplete,$true)
|
||||
})]
|
||||
[string[]]$ImportFunction,
|
||||
[ArgumentCompleter({ param (
|
||||
$commandName,
|
||||
$parameterName,
|
||||
$wordToComplete,
|
||||
$commandAst,
|
||||
$fakeBoundParameters
|
||||
)
|
||||
[SystemName]::_GetValidValues($wordToComplete,$false,$true)
|
||||
})]
|
||||
[string]$System,
|
||||
[switch]$ForceImport,
|
||||
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
|
||||
[ArgumentCompleter({ param (
|
||||
$commandName,
|
||||
$parameterName,
|
||||
$wordToComplete,
|
||||
$commandAst,
|
||||
$fakeBoundParameters
|
||||
)
|
||||
$local:possibleValues = [MyScript]::_GetValidValues($wordToComplete,$true)
|
||||
if( $fakeBoundParameters.ContainsKey("System") ) {
|
||||
$possibleValues = $possibleValues | Where-Object { $_ -match "^sys\.$($fakeBoundParameters.System)" } | ForEach-Object { $_ -replace "^sys\.$($fakeBoundParameters.System).",'' }
|
||||
}
|
||||
$possibleValues
|
||||
})]
|
||||
[string[]]$ScriptName
|
||||
)
|
||||
|
||||
$local:EditRootPath=$MyPSScriptRoot
|
||||
if( $System ) {
|
||||
$EditRootPath = Join-Path $EditRootPath "sys.$System"
|
||||
}
|
||||
$local:ScriptPaths = @()
|
||||
foreach( $local:p in $ImportFunction ) {
|
||||
$local:f = Get-Command $p -Type Function
|
||||
if( $f ) {
|
||||
$local:sp = Join-Path $EditRootPath "$p`.ps1"
|
||||
if( $ForceImport -or -not (Test-Path $sp) ) {
|
||||
Export-FunctionSource $p -NoHeader > $sp
|
||||
} elseif ( -not $ForceImport ) {
|
||||
throw "$p already exists in Script, to import the function again, use the -Force"
|
||||
}
|
||||
$ScriptPaths += $sp
|
||||
}
|
||||
}
|
||||
foreach( $local:p in $ScriptName ) {
|
||||
$local:sp = Join-Path $EditRootPath "$p`.ps1"
|
||||
$ScriptPaths += $sp
|
||||
}
|
||||
|
||||
if( -not $ScriptPaths ) {
|
||||
$ScriptPaths += $EditRootPath
|
||||
}
|
||||
|
||||
foreach( $local:p in $ScriptPaths ) {
|
||||
$local:parentPath = Split-Path -Parent $p;
|
||||
if( -not (Test-Path $p) -and -not (Test-Path $parentPath) ) {
|
||||
Write-Verbose "Creating missing path $parentPath..."
|
||||
New-Item -Type Directory $parentPath
|
||||
}
|
||||
}
|
||||
|
||||
$local:sw = [System.Diagnostics.Stopwatch]::StartNew();
|
||||
Edit-TextFile $ScriptPaths
|
||||
$sw.Stop();
|
||||
|
||||
if( $sw.Elapsed.TotalSeconds -lt 1 ) {
|
||||
$null = Read-Host "Waiting before refreshing. Press <Enter> when you're done editing ( don't forget to save ;) )..."
|
||||
}
|
||||
|
||||
Get-Command Reload-MyScripts -ErrorAction SilentlyContinue |
|
||||
ForEach-Object { . $_.Definition }
|
Loading…
Add table
Add a link
Reference in a new issue