mirror of
https://github.com/tw93/Mole.git
synced 2026-02-15 19:50:04 +00:00
refactor(windows): fix cmdlet shadowing and enforce dependency isolation
This commit is contained in:
2
go.mod
2
go.mod
@@ -19,7 +19,6 @@ require (
|
||||
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
|
||||
github.com/charmbracelet/x/term v0.2.1 // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
@@ -34,7 +33,6 @@ require (
|
||||
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
golang.org/x/sys v0.36.0 // indirect
|
||||
golang.org/x/text v0.3.8 // indirect
|
||||
)
|
||||
|
||||
@@ -202,7 +202,7 @@ function Start-Cleanup {
|
||||
# System cleanup confirmation
|
||||
if ($IncludeSystem -and -not $IsDryRun) {
|
||||
if (-not (Test-IsAdmin)) {
|
||||
Write-Warning "System cleanup requires administrator privileges"
|
||||
Write-MoleWarning "System cleanup requires administrator privileges"
|
||||
Write-Host " Run PowerShell as Administrator for full cleanup"
|
||||
Write-Host ""
|
||||
$IncludeSystem = $false
|
||||
@@ -245,7 +245,7 @@ function Start-Cleanup {
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Cleanup error: $_"
|
||||
Write-MoleError "Cleanup error: $_"
|
||||
}
|
||||
|
||||
# Get final stats
|
||||
|
||||
@@ -313,7 +313,7 @@ function Show-ProjectSelectionMenu {
|
||||
|
||||
$projectCount = if ($null -eq $Projects) { 0 } else { @($Projects).Count }
|
||||
if ($projectCount -eq 0) {
|
||||
Write-Warning "No projects with cleanable artifacts found"
|
||||
Write-MoleWarning "No projects with cleanable artifacts found"
|
||||
return @()
|
||||
}
|
||||
|
||||
@@ -549,7 +549,7 @@ function Main {
|
||||
$searchPaths = @(Get-SearchPaths)
|
||||
|
||||
if ($null -eq $searchPaths -or $searchPaths.Count -eq 0) {
|
||||
Write-Warning "No valid search paths found"
|
||||
Write-MoleWarning "No valid search paths found"
|
||||
Write-Host "Run 'mole purge -Paths' to configure search directories"
|
||||
return
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ function Show-AppSelectionMenu {
|
||||
param([array]$Apps)
|
||||
|
||||
if ($Apps.Count -eq 0) {
|
||||
Write-Warning "No applications found to uninstall"
|
||||
Write-MoleWarning "No applications found to uninstall"
|
||||
return @()
|
||||
}
|
||||
|
||||
@@ -583,7 +583,7 @@ function Main {
|
||||
$apps = Get-InstalledApplications -ForceRescan:$Rescan
|
||||
|
||||
if ($apps.Count -eq 0) {
|
||||
Write-Warning "No applications found"
|
||||
Write-MoleWarning "No applications found"
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -3,32 +3,8 @@ module github.com/tw93/mole/windows
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
github.com/charmbracelet/bubbletea v0.25.0
|
||||
github.com/charmbracelet/lipgloss v0.9.1
|
||||
github.com/charmbracelet/bubbletea v1.3.10
|
||||
github.com/shirou/gopsutil/v3 v3.24.5
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.18 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/muesli/reflow v0.3.0 // indirect
|
||||
github.com/muesli/termenv v0.15.2 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
github.com/shoenig/go-m1cpu v0.1.7 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
golang.org/x/term v0.6.0 // indirect
|
||||
golang.org/x/text v0.3.8 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4
|
||||
golang.org/x/sys v0.36.0
|
||||
)
|
||||
|
||||
@@ -55,13 +55,13 @@ function Write-Success {
|
||||
Write-Host " $($c.Green)OK$($c.NC) $Message"
|
||||
}
|
||||
|
||||
function Write-Warning {
|
||||
function Write-MoleWarning {
|
||||
param([string]$Message)
|
||||
$c = $script:Colors
|
||||
Write-Host " $($c.Yellow)WARN$($c.NC) $Message"
|
||||
}
|
||||
|
||||
function Write-Error {
|
||||
function Write-MoleError {
|
||||
param([string]$Message)
|
||||
$c = $script:Colors
|
||||
Write-Host " $($c.Red)ERROR$($c.NC) $Message"
|
||||
@@ -144,7 +144,7 @@ function Add-ToUserPath {
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to update PATH: $_"
|
||||
Write-MoleError "Failed to update PATH: $_"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ function Remove-FromUserPath {
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to update PATH: $_"
|
||||
Write-MoleError "Failed to update PATH: $_"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ function New-StartMenuShortcut {
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to create shortcut: $_"
|
||||
Write-MoleError "Failed to create shortcut: $_"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
@@ -215,7 +215,7 @@ function Remove-StartMenuShortcut {
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to remove shortcut: $_"
|
||||
Write-MoleError "Failed to remove shortcut: $_"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
@@ -233,7 +233,7 @@ function Install-Mole {
|
||||
|
||||
# Check if already installed
|
||||
if ((Test-Path $InstallDir) -and -not $Force) {
|
||||
Write-Error "Mole is already installed at: $InstallDir"
|
||||
Write-MoleError "Mole is already installed at: $InstallDir"
|
||||
Write-Host ""
|
||||
Write-Host " Use -Force to overwrite or -Uninstall to remove first"
|
||||
Write-Host ""
|
||||
@@ -247,7 +247,7 @@ function Install-Mole {
|
||||
Write-Success "Created directory: $InstallDir"
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to create directory: $_"
|
||||
Write-MoleError "Failed to create directory: $_"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ function Install-Mole {
|
||||
Write-Success "Copied: $item"
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to copy $item`: $_"
|
||||
Write-MoleError "Failed to copy $item`: $_"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
@@ -366,7 +366,7 @@ function Uninstall-Mole {
|
||||
$installPath = if (Test-Path $InstallDir) { $InstallDir } elseif (Test-Path $configPath) { $configPath } else { $null }
|
||||
|
||||
if (-not $installPath) {
|
||||
Write-Warning "Mole is not installed"
|
||||
Write-MoleWarning "Mole is not installed"
|
||||
return $true
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ function Uninstall-Mole {
|
||||
Write-Success "Removed directory: $installPath"
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to remove directory: $_"
|
||||
Write-MoleError "Failed to remove directory: $_"
|
||||
return $false
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ function Uninstall-Mole {
|
||||
Write-Success "Removed config: $configDir"
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Failed to remove config: $_"
|
||||
Write-MoleWarning "Failed to remove config: $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ function Invoke-SystemCleanup {
|
||||
Start-Section "System cleanup"
|
||||
|
||||
if (-not (Test-IsAdmin)) {
|
||||
Write-Warning "Running without admin - some cleanup tasks will be skipped"
|
||||
Write-MoleWarning "Running without admin - some cleanup tasks will be skipped"
|
||||
}
|
||||
|
||||
# System temp files
|
||||
|
||||
@@ -90,7 +90,7 @@ function Request-AdminPrivileges {
|
||||
Restarts the script with elevated privileges using UAC
|
||||
#>
|
||||
if (-not (Test-IsAdmin)) {
|
||||
Write-Warning "Some operations require administrator privileges."
|
||||
Write-MoleWarning "Some operations require administrator privileges."
|
||||
|
||||
if (Read-Confirmation -Prompt "Restart with admin privileges?" -Default $true) {
|
||||
$scriptPath = $MyInvocation.PSCommandPath
|
||||
|
||||
@@ -71,7 +71,8 @@ function Write-Success {
|
||||
Write-LogMessage -Message $Message -Level "SUCCESS" -Color "Green" -Icon $script:Icons.Success
|
||||
}
|
||||
|
||||
function Write-Warning {
|
||||
|
||||
function Write-MoleWarning {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Write a warning message
|
||||
@@ -80,7 +81,7 @@ function Write-Warning {
|
||||
Write-LogMessage -Message $Message -Level "WARN" -Color "Yellow" -Icon $script:Icons.Warning
|
||||
}
|
||||
|
||||
function Write-Error {
|
||||
function Write-MoleError {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Write an error message
|
||||
@@ -89,6 +90,7 @@ function Write-Error {
|
||||
Write-LogMessage -Message $Message -Level "ERROR" -Color "Red" -Icon $script:Icons.Error
|
||||
}
|
||||
|
||||
|
||||
function Write-Debug {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
|
||||
@@ -155,7 +155,7 @@ function Invoke-MoleCommand {
|
||||
$scriptPath = Join-Path $script:MOLE_BIN "$CommandName.ps1"
|
||||
|
||||
if (-not (Test-Path $scriptPath)) {
|
||||
Write-Error "Unknown command: $CommandName"
|
||||
Write-MoleError "Unknown command: $CommandName"
|
||||
Write-Host ""
|
||||
Write-Host "Run 'mole -ShowHelp' for available commands"
|
||||
return
|
||||
@@ -269,7 +269,7 @@ function Main {
|
||||
Invoke-MoleCommand -CommandName $effectiveCommand -Arguments $CommandArgs
|
||||
}
|
||||
else {
|
||||
Write-Error "Unknown command: $effectiveCommand"
|
||||
Write-MoleError "Unknown command: $effectiveCommand"
|
||||
Write-Host ""
|
||||
Write-Host "Available commands: $($validCommands -join ', ')"
|
||||
Write-Host "Run 'mole -ShowHelp' for more information"
|
||||
@@ -311,7 +311,7 @@ try {
|
||||
}
|
||||
catch {
|
||||
Write-Host ""
|
||||
Write-Error "An error occurred: $_"
|
||||
Write-MoleError "An error occurred: $_"
|
||||
Write-Host ""
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -192,14 +192,14 @@ Describe "Logging Module" {
|
||||
{ Write-Success "Test message" } | Should -Not -Throw
|
||||
}
|
||||
|
||||
It "Should have Write-Warning function" {
|
||||
# Note: The actual function is Write-Warning (conflicts with built-in)
|
||||
{ Write-Warning "Test message" } | Should -Not -Throw
|
||||
It "Should have Write-MoleWarning function" {
|
||||
# Note: The actual function is Write-MoleWarning
|
||||
{ Write-MoleWarning "Test message" } | Should -Not -Throw
|
||||
}
|
||||
|
||||
It "Should have Write-Error function" {
|
||||
# Note: The actual function is Write-Error (conflicts with built-in)
|
||||
{ Write-Error "Test message" } | Should -Not -Throw
|
||||
It "Should have Write-MoleError function" {
|
||||
# Note: The actual function is Write-MoleError
|
||||
{ Write-MoleError "Test message" } | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user