Skip to content

Commit

Permalink
Refactor script execution logic to handle multiple paths and recursiv…
Browse files Browse the repository at this point in the history
…e search for .ps1 files

Signed-off-by: PixelRobots <22979170+PixelRobots@users.noreply.github.com>
  • Loading branch information
PixelRobots committed Oct 17, 2024
1 parent 8b5c05d commit 6834568
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions KubeTidy.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ if (Test-Path "$PSScriptRoot\Private") {
Write-Verbose "Path $PSScriptRoot\Private does not exist."
}

# If the first path fails, try the second path
# If the first path fails, try the second path with recursion to handle versioned folders
if (-not $scriptExecuted) {
if (Test-Path "$HOME/.krew/store/kubetidy") {
try {
Write-Verbose "Trying to execute scripts from: $HOME/.krew/store/kubetidy"
Get-ChildItem -Path "$HOME/.krew/store/kubetidy\*.ps1" 2>$null | ForEach-Object {
Write-Verbose "Trying to execute scripts recursively from: $HOME/.krew/store/kubetidy"

# Recursively look for .ps1 files inside the versioned directories
Get-ChildItem -Path "$HOME/.krew/store/kubetidy\*.ps1" -Recurse 2>$null | ForEach-Object {
. $_.FullName
}
$scriptExecuted = $true
Expand Down

0 comments on commit 6834568

Please sign in to comment.