2020-09-18 19:41:58 +00:00
|
|
|
[CmdletBinding(SupportsShouldProcess)]param(
|
|
|
|
[ArgumentCompleter({ param (
|
|
|
|
$commandName,
|
|
|
|
$parameterName,
|
|
|
|
$wordToComplete,
|
|
|
|
$commandAst,
|
|
|
|
$fakeBoundParameters
|
|
|
|
)
|
|
|
|
[FunctionName]::_GetValidValues($wordToComplete,$true)
|
|
|
|
})]
|
|
|
|
[string[]]$ImportFunction,
|
2020-10-02 16:45:04 +00:00
|
|
|
[ArgumentCompleter({ param (
|
|
|
|
$commandName,
|
|
|
|
$parameterName,
|
|
|
|
$wordToComplete,
|
|
|
|
$commandAst,
|
|
|
|
$fakeBoundParameters
|
|
|
|
)
|
2020-11-25 05:46:33 +00:00
|
|
|
$local:NotAll = $true
|
|
|
|
if( $fakeBoundParameters.ContainsKey("All") ) { $NotAll = -not $fakeBoundParameters.All }
|
|
|
|
[Packagesz]::_GetValidValues($wordToComplete,$NotAll,$true)
|
2020-10-02 16:45:04 +00:00
|
|
|
})]
|
2020-11-25 05:46:33 +00:00
|
|
|
[string]$Package,
|
2020-09-18 19:41:58 +00:00
|
|
|
[switch]$ForceImport,
|
2020-11-25 05:46:33 +00:00
|
|
|
[switch]$All,
|
2020-09-18 19:41:58 +00:00
|
|
|
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
|
|
|
|
[ArgumentCompleter({ param (
|
|
|
|
$commandName,
|
|
|
|
$parameterName,
|
|
|
|
$wordToComplete,
|
|
|
|
$commandAst,
|
|
|
|
$fakeBoundParameters
|
|
|
|
)
|
2020-11-25 05:46:33 +00:00
|
|
|
$local:NotAll = $true
|
|
|
|
$local:Pkg = [string]::Empty
|
|
|
|
if( $fakeBoundParameters.ContainsKey("All") ) { $NotAll = -not $fakeBoundParameters.All }
|
|
|
|
if( $fakeBoundParameters.ContainsKey("Package") ) { $Pkg = Join-Path $fakeBoundParameters.Package '' }
|
|
|
|
$local:possibleValues = [MyScript]::_GetValidValues($wordToComplete,$NotAll,$true)
|
|
|
|
if( $Pkg ) {
|
|
|
|
$possibleValues = $possibleValues |
|
|
|
|
Where-Object { $_ -match "^$Pkg" } |
|
|
|
|
ForEach-Object { $_.Replace($Pkg,'') }
|
2020-10-02 16:45:04 +00:00
|
|
|
}
|
2020-11-25 05:46:33 +00:00
|
|
|
|
2020-10-02 16:45:04 +00:00
|
|
|
$possibleValues
|
2020-09-18 19:41:58 +00:00
|
|
|
})]
|
2020-12-05 23:18:12 +00:00
|
|
|
[string[]]$ScriptName,
|
|
|
|
[switch]$WaitNotRequired = $env:WAIT_NOT_REQUIRED
|
2020-09-18 19:41:58 +00:00
|
|
|
)
|
|
|
|
|
2020-10-02 16:45:04 +00:00
|
|
|
$local:EditRootPath=$MyPSScriptRoot
|
2020-11-25 05:46:33 +00:00
|
|
|
if( $Package ) {
|
|
|
|
$EditRootPath = Join-Path $EditRootPath $Package
|
2020-10-02 16:45:04 +00:00
|
|
|
}
|
2020-09-18 19:41:58 +00:00
|
|
|
$local:ScriptPaths = @()
|
|
|
|
foreach( $local:p in $ImportFunction ) {
|
2021-04-27 16:04:12 +00:00
|
|
|
$local:f = Get-Command -ListImported $p -Type Function
|
2020-09-18 19:41:58 +00:00
|
|
|
if( $f ) {
|
2020-10-02 16:45:04 +00:00
|
|
|
$local:sp = Join-Path $EditRootPath "$p`.ps1"
|
2020-09-18 19:41:58 +00:00
|
|
|
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 ) {
|
2020-10-02 16:45:04 +00:00
|
|
|
$local:sp = Join-Path $EditRootPath "$p`.ps1"
|
2020-09-18 19:41:58 +00:00
|
|
|
$ScriptPaths += $sp
|
|
|
|
}
|
|
|
|
|
2020-09-25 05:04:05 +00:00
|
|
|
if( -not $ScriptPaths ) {
|
2020-10-02 16:45:04 +00:00
|
|
|
$ScriptPaths += $EditRootPath
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach( $local:p in $ScriptPaths ) {
|
|
|
|
$local:parentPath = Split-Path -Parent $p;
|
|
|
|
if( -not (Test-Path $p) -and -not (Test-Path $parentPath) ) {
|
2020-10-03 20:17:11 +00:00
|
|
|
Write-Verbose "Creating missing path $parentPath..."
|
|
|
|
New-Item -Type Directory $parentPath
|
2020-10-02 16:45:04 +00:00
|
|
|
}
|
2020-09-25 05:04:05 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 18:06:17 +00:00
|
|
|
$local:sw = [System.Diagnostics.Stopwatch]::StartNew();
|
2020-09-18 19:41:58 +00:00
|
|
|
Edit-TextFile $ScriptPaths
|
2020-11-09 18:06:17 +00:00
|
|
|
$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 ;) )..."
|
|
|
|
}
|
2020-09-18 19:41:58 +00:00
|
|
|
|
2021-04-27 16:04:12 +00:00
|
|
|
Get-Command -ListImported Reload-MyScripts -ErrorAction SilentlyContinue |
|
2020-09-18 19:41:58 +00:00
|
|
|
ForEach-Object { . $_.Definition }
|