Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions private/Get-Commands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ function Get-Commands {
)
)
[Command]::new("version", { Write-Host (Get-MyModuleVersion) })
[Command]::new("update", {
Write-Host "updating quickpath..."
Update-Module quickpath
Write-Host "quickpath has been updated"
})
[Command]::new("update", "Update-QuickPath")
)
}
return $script:CachedCommands
Expand Down
99 changes: 99 additions & 0 deletions private/Update-QuickPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
function Update-QuickPath {
try {
Update-Module -Name quickpath -Force -ErrorAction Stop
Import-Module quickpath -Force -ErrorAction Stop
Write-Host "quickpath updated from gallery and reloaded." -ForegroundColor Green
}
catch {
Write-Error "Failed to update quickpath from gallery: $($_.Exception.Message)"
throw
}
# [CmdletBinding()]
# param(
# [ValidateSet('Patch', 'Minor', 'Major')]
# [string]$Increment = 'Patch',

# [switch]$SkipTests,

# # Force update from the PowerShell Gallery instead of local source
# [switch]$FromGallery
# )

# try {
# Write-Host "Updating quickpath..." -ForegroundColor Cyan

# if ($FromGallery) {

# Update-QuickPathFromGallery
# return
# }

# $buildFile = Get-BuildFile

# if (-not $buildFile) {
# Write-Verbose "Build script not found near '$startPath'; falling back to gallery update."
# Update-QuickPathFromGallery
# return
# }

# ValidateOrInstallTools

# # Build argument list for Invoke-Build
# $tasks = @()
# if (-not $SkipTests) { $tasks += 'Test' }
# $tasks += 'Refresh'

# # Execute build in the current session so Import-Module in Refresh affects this session
# Invoke-Build -File $buildFile -Increment $Increment -Task $tasks

# # As an extra safety, try re-importing the freshly built manifest
# $outManifest = Join-Path (Split-Path $buildFile -Parent) 'output\quickpath\quickpath.psd1'
# if (Test-Path $outManifest) {
# Import-Module $outManifest -Force -ErrorAction SilentlyContinue
# }

# Write-Host "quickpath has been built, tested, and reloaded." -ForegroundColor Green
# }
# catch {
# Write-Error "Failed to update quickpath: $($_.Exception.Message)"
# throw
# }
}

# function Update-QuickPathFromGallery {
# try {
# Update-Module -Name quickpath -Force -ErrorAction Stop
# Import-Module quickpath -Force -ErrorAction Stop
# Write-Host "quickpath updated from gallery and reloaded." -ForegroundColor Green
# }
# catch {
# Write-Error "Failed to update quickpath from gallery: $($_.Exception.Message)"
# throw
# }
# }

# function Get-BuildFile {
# $startPath = (Get-Location).Path
# $dir = $startPath
# $buildFile = $null
# for ($i = 0; $i -lt 6; $i++) {
# $candidate = Join-Path $dir 'quickpath.build.ps1'
# if (Test-Path $candidate) { $buildFile = $candidate; break }
# $parent = Split-Path $dir -Parent
# if ([string]::IsNullOrEmpty($parent) -or $parent -eq $dir) { break }
# $dir = $parent
# }
# return $buildFile
# }

# function ValidateOrInstallTools {
# # Ensure required tools are available
# if (-not (Get-Module -ListAvailable -Name InvokeBuild)) {
# Write-Verbose "Installing InvokeBuild..."
# Install-Module -Name InvokeBuild -Scope CurrentUser -Force -ErrorAction Stop
# }
# if (-not (Get-Module -ListAvailable -Name Pester)) {
# Write-Verbose "Installing Pester..."
# Install-Module -Name Pester -Scope CurrentUser -Force -ErrorAction Stop
# }
# }
31 changes: 31 additions & 0 deletions tests/Update-QuickPath.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Context 'Update-QuickPath' {
BeforeAll {
. $PSScriptRoot\..\private\Update-QuickPath.ps1
}
It 'Should call Update-Module and Import-Module' {
Mock Update-Module
Mock Import-Module
Mock Write-Host
Update-QuickPath

Assert-MockCalled -CommandName Update-Module -Times 1 -Exactly -Scope It -ParameterFilter {
$Name -eq 'quickpath' -and $Force -eq $true -and $ErrorAction -eq 'Stop'
}

Assert-MockCalled -CommandName Import-Module -Times 1 -Exactly -Scope It -ParameterFilter {
$Name -eq 'quickpath' -and $Force -eq $true -and $ErrorAction -eq 'Stop'
}

Assert-MockCalled -CommandName Write-Host -Times 1 -Exactly -Scope It -ParameterFilter {
$Object -eq "quickpath updated from gallery and reloaded." -and $ForegroundColor -eq 'Green'
}
}
It 'Should handle errors from Update-Module' {
Mock Update-Module { throw [System.Exception]::new("Update failed") }
Mock Write-Error
{ Update-QuickPath } | Should -Throw

Assert-MockCalled -CommandName Write-Error -Times 1 -Exactly -Scope It
}
}