1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-16 07:11:11 +00:00

Optimize CLI: consolidate repairs and standardize flags

This commit is contained in:
Tw93
2026-01-16 15:08:42 +08:00
parent 3240cc7a69
commit e9cddbf4af
5 changed files with 208 additions and 223 deletions

View File

@@ -68,40 +68,40 @@ git checkout windows
Run: Run:
```powershell ```powershell
mole # Interactive menu mo # Interactive menu
mole clean # Deep cleanup mo clean # Deep cleanup
mole uninstall # Remove apps + leftovers mo uninstall # Remove apps + leftovers
mole optimize # Refresh caches & services mo optimize # Refresh caches & services
mole analyze # Visual disk explorer mo analyze # Visual disk explorer
mole status # Live system health dashboard mo status # Live system health dashboard
mole purge # Clean project build artifacts mo purge # Clean project build artifacts
mole -ShowHelp # Show help mo --help # Show help
mole -Version # Show installed version mo --version # Show installed version
mole clean -DryRun # Preview the cleanup plan mo clean --dry-run # Preview the cleanup plan
mole clean -Whitelist # Manage protected caches mo clean --whitelist # Manage protected caches
mole clean -DryRun -Debug # Detailed preview with risk levels mo clean --dry-run --debug # Detailed preview with risk levels
mole optimize -DryRun # Preview optimization actions mo optimize --dry-run # Preview optimization actions
mole optimize -Debug # Run with detailed operation logs mo optimize --debug # Run with detailed operation logs
mole purge -Paths # Configure project scan directories mo purge --paths # Configure project scan directories
``` ```
## Tips ## Tips
- **Safety**: Built with strict protections. Preview changes with `mole clean -DryRun`. - **Safety**: Built with strict protections. Preview changes with `mo clean --dry-run`.
- **Be Careful**: Although safe by design, file deletion is permanent. Please review operations carefully. - **Be Careful**: Although safe by design, file deletion is permanent. Please review operations carefully.
- **Debug Mode**: Use `-Debug` for detailed logs (e.g., `mole clean -Debug`). Combine with `-DryRun` for comprehensive preview including risk levels and file details. - **Debug Mode**: Use `--debug` for detailed logs (e.g., `mo clean --debug`). Combine with `--dry-run` for comprehensive preview including risk levels and file details.
- **Navigation**: Supports arrow keys for TUI navigation. - **Navigation**: Supports arrow keys for TUI navigation.
- **Configuration**: Use `mole clean -Whitelist` to manage protected paths, `mole purge -Paths` to configure scan directories. - **Configuration**: Use `mo clean --whitelist` to manage protected paths, `mo purge --paths` to configure scan directories.
## Features in Detail ## Features in Detail
### Deep System Cleanup ### Deep System Cleanup
```powershell ```powershell
mole clean mo clean
``` ```
``` ```
@@ -122,7 +122,7 @@ Space freed: 56.1GB | Free space now: 180.3GB
### Smart App Uninstaller ### Smart App Uninstaller
```powershell ```powershell
mole uninstall mo uninstall
``` ```
``` ```
@@ -148,7 +148,7 @@ Space freed: 4.8GB
### System Optimization ### System Optimization
```powershell ```powershell
mole optimize mo optimize
``` ```
``` ```
@@ -160,6 +160,7 @@ System: 12/32 GB RAM | 280/460 GB Disk (61%) | Uptime 6d
✓ Refresh Windows Search index ✓ Refresh Windows Search index
✓ Clear thumbnail cache ✓ Clear thumbnail cache
✓ Optimize startup programs ✓ Optimize startup programs
✓ System repairs (Font/Icon/Store/Search)
==================================================================== ====================================================================
System optimization completed System optimization completed
@@ -169,7 +170,7 @@ System optimization completed
### Disk Space Analyzer ### Disk Space Analyzer
```powershell ```powershell
mole analyze mo analyze
``` ```
``` ```
@@ -189,7 +190,7 @@ Analyze Disk C:\Users\YourName\Documents | Total: 156.8GB
Real-time dashboard with system health score, hardware info, and performance metrics. Real-time dashboard with system health score, hardware info, and performance metrics.
```powershell ```powershell
mole status mo status
``` ```
``` ```
@@ -219,7 +220,7 @@ Health score based on CPU, memory, disk, temperature, and I/O load. Color-coded
Clean old build artifacts (`node_modules`, `target`, `build`, `dist`, etc.) from your projects to free up disk space. Clean old build artifacts (`node_modules`, `target`, `build`, `dist`, etc.) from your projects to free up disk space.
```powershell ```powershell
mole purge mo purge
``` ```
``` ```
@@ -237,7 +238,7 @@ Select Categories to Clean - 18.5GB (8 selected)
Use with caution: This will permanently delete selected artifacts. Review carefully before confirming. Recent projects — less than 7 days old — are marked and unselected by default. Use with caution: This will permanently delete selected artifacts. Review carefully before confirming. Recent projects — less than 7 days old — are marked and unselected by default.
Custom scan paths can be configured with `mole purge -Paths`. Custom scan paths can be configured with `mo purge --paths`.
## Installation Options ## Installation Options

View File

@@ -4,11 +4,22 @@
#Requires -Version 5.1 #Requires -Version 5.1
[CmdletBinding()] [CmdletBinding()]
param( param(
[Alias('dry-run')]
[switch]$DryRun, [switch]$DryRun,
[Alias('system')]
[switch]$System, [switch]$System,
[Alias('game-media')]
[switch]$GameMedia, [switch]$GameMedia,
[Alias('debug')]
[switch]$DebugMode, [switch]$DebugMode,
[Alias('whitelist')]
[switch]$Whitelist, [switch]$Whitelist,
[Alias('help')]
[switch]$ShowHelp [switch]$ShowHelp
) )

View File

@@ -4,15 +4,14 @@
#Requires -Version 5.1 #Requires -Version 5.1
[CmdletBinding()] [CmdletBinding()]
param( param(
[Alias('dry-run')]
[switch]$DryRun, [switch]$DryRun,
[Alias('debug')]
[switch]$DebugMode, [switch]$DebugMode,
[switch]$ShowHelp,
# Repair options [Alias('help')]
[switch]$Repair, [switch]$ShowHelp
[switch]$Font,
[switch]$Icon,
[switch]$Search,
[switch]$Store
) )
Set-StrictMode -Version Latest Set-StrictMode -Version Latest
@@ -44,36 +43,25 @@ $script:IssuesFixed = 0
function Show-OptimizeHelp { function Show-OptimizeHelp {
$esc = [char]27 $esc = [char]27
Write-Host "" Write-Host ""
Write-Host "$esc[1;35mMole Optimize$esc[0m - System optimization, health checks, and repairs" Write-Host "$esc[1;35mMole Optimize$esc[0m - System optimization and repairs"
Write-Host "" Write-Host ""
Write-Host "$esc[33mUsage:$esc[0m mole optimize [options]" Write-Host "$esc[33mUsage:$esc[0m mo optimize [options]"
Write-Host "" Write-Host ""
Write-Host "$esc[33mOptions:$esc[0m" Write-Host "$esc[33mOptions:$esc[0m"
Write-Host " -DryRun Preview changes without applying" Write-Host " --dry-run Preview changes without applying"
Write-Host " -DebugMode Enable debug logging" Write-Host " --debug Enable debug logging"
Write-Host " -ShowHelp Show this help message" Write-Host " --help Show this help message"
Write-Host "" Write-Host ""
Write-Host "$esc[33mRepair Options:$esc[0m" Write-Host "$esc[33mWhat it does:$esc[0m"
Write-Host " -Repair Run all repairs (Font, Icon, Search, Store)" Write-Host " - Disk optimization (TRIM/Defrag)"
Write-Host " -Font Rebuild font cache (fixes font display issues)" Write-Host " - Windows Search & Update check"
Write-Host " -Icon Rebuild icon cache (fixes missing/corrupt icons)" Write-Host " - Network & DNS optimization"
Write-Host " -Search Reset Windows Search index (fixes search issues)" Write-Host " - System cache cleanup & repairs"
Write-Host " -Store Reset Windows Store cache (fixes Store issues)" Write-Host " (Font cache, Icon cache, Store cache)"
Write-Host "" Write-Host ""
Write-Host "$esc[33mExamples:$esc[0m" Write-Host "$esc[33mExamples:$esc[0m"
Write-Host " mole optimize # Run standard optimizations" Write-Host " mo optimize # Run all optimizations"
Write-Host " mole optimize -Repair # Run optimizations + all repairs" Write-Host " mo optimize --dry-run # Preview what would happen"
Write-Host " mole optimize -Icon -Font # Run optimizations + specific repairs"
Write-Host " mole optimize -DryRun # Preview what would happen"
Write-Host ""
Write-Host "$esc[33mOptimizations (always run):$esc[0m"
Write-Host " - Disk defragmentation/TRIM (SSD optimization)"
Write-Host " - Windows Search index check"
Write-Host " - DNS cache flush"
Write-Host " - Network optimization"
Write-Host " - Startup program analysis"
Write-Host " - Disk health check"
Write-Host " - Windows Update status"
Write-Host "" Write-Host ""
} }
@@ -757,9 +745,6 @@ function Main {
# Set dry-run mode # Set dry-run mode
$script:DryRun = $DryRun $script:DryRun = $DryRun
# Check if any repairs were requested
$runRepairs = $Repair -or $Font -or $Icon -or $Search -or $Store
# Clear screen # Clear screen
Clear-Host Clear-Host
@@ -788,30 +773,17 @@ function Main {
Test-DiskHealth Test-DiskHealth
Test-WindowsUpdate Test-WindowsUpdate
# Run repairs if requested # Run repairs (consolidated)
if ($runRepairs) { Write-Host ""
Write-Host "" Write-Host "$esc[34m$($script:Icons.Arrow) System Repairs$esc[0m"
Write-Host "$esc[1;35m$($script:Icons.Arrow) Repairs$esc[0m"
if ($Repair -or $Font) { Repair-FontCache
Repair-FontCache Repair-StoreCache
} Repair-SearchIndex
Repair-IconCache
if ($Repair -or $Icon) { # System file check is slow, ask first
Repair-IconCache if (-not $script:DryRun -and (Test-IsAdmin)) {
}
if ($Repair -or $Search) {
Repair-SearchIndex
}
if ($Repair -or $Store) {
Repair-StoreCache
}
}
# System file check is slow, ask first (only if not doing repairs)
if (-not $runRepairs -and -not $script:DryRun -and (Test-IsAdmin)) {
Write-Host "" Write-Host ""
$runSfc = Read-Host "Run System File Checker? This may take several minutes (y/N)" $runSfc = Read-Host "Run System File Checker? This may take several minutes (y/N)"
if ($runSfc -eq 'y' -or $runSfc -eq 'Y') { if ($runSfc -eq 'y' -or $runSfc -eq 'Y') {

View File

@@ -4,8 +4,13 @@
#Requires -Version 5.1 #Requires -Version 5.1
[CmdletBinding()] [CmdletBinding()]
param( param(
[Alias('debug')]
[switch]$DebugMode, [switch]$DebugMode,
[Alias('paths')]
[switch]$Paths, [switch]$Paths,
[Alias('help')]
[switch]$ShowHelp [switch]$ShowHelp
) )

View File

@@ -57,37 +57,33 @@ function Show-MainHelp {
Write-Host "" Write-Host ""
Write-Host " ${green}COMMANDS:${nc}" Write-Host " ${green}COMMANDS:${nc}"
Write-Host "" Write-Host ""
Write-Host " ${cyan}clean${nc} Deep system cleanup (caches, temp, logs)" Write-Host " ${cyan}clean${nc} Deep system cleanup"
Write-Host " ${cyan}uninstall${nc} Smart application uninstaller" Write-Host " ${cyan}uninstall${nc} Smart application uninstaller"
Write-Host " ${cyan}analyze${nc} Visual disk space analyzer"
Write-Host " ${cyan}status${nc} Real-time system monitor"
Write-Host " ${cyan}optimize${nc} System optimization and repairs" Write-Host " ${cyan}optimize${nc} System optimization and repairs"
Write-Host " ${cyan}purge${nc} Clean project build artifacts" Write-Host " ${cyan}analyze${nc} Disk space analyzer"
Write-Host " ${cyan}status${nc} System monitor"
Write-Host " ${cyan}purge${nc} Clean project artifacts"
Write-Host "" Write-Host ""
Write-Host " ${green}OPTIONS:${nc}" Write-Host " ${green}OPTIONS:${nc}"
Write-Host "" Write-Host ""
Write-Host " ${cyan}-Version${nc} Show version information" Write-Host " ${cyan}--version${nc} Show version information"
Write-Host " ${cyan}-ShowHelp${nc} Show this help message" Write-Host " ${cyan}--help${nc} Show this help message"
Write-Host "" Write-Host ""
Write-Host " ${green}EXAMPLES:${nc}" Write-Host " ${green}EXAMPLES:${nc}"
Write-Host "" Write-Host ""
Write-Host " ${gray}mole${nc} ${gray}# Interactive menu${nc}" Write-Host " ${gray}mo${nc} ${gray}# Interactive menu${nc}"
Write-Host " ${gray}mole clean${nc} ${gray}# Deep cleanup${nc}" Write-Host " ${gray}mo clean${nc} ${gray}# Deep cleanup${nc}"
Write-Host " ${gray}mole clean -DryRun${nc} ${gray}# Preview cleanup${nc}" Write-Host " ${gray}mo clean --dry-run${nc} ${gray}# Preview cleanup${nc}"
Write-Host " ${gray}mole uninstall${nc} ${gray}# Uninstall apps${nc}" Write-Host " ${gray}mo optimize${nc} ${gray}# Optimize system${nc}"
Write-Host " ${gray}mole analyze${nc} ${gray}# Disk analyzer${nc}" Write-Host " ${gray}mo optimize --dry-run${nc} ${gray}# Preview optimization${nc}"
Write-Host " ${gray}mole status${nc} ${gray}# System monitor${nc}" Write-Host " ${gray}mo uninstall${nc} ${gray}# Uninstall apps${nc}"
Write-Host " ${gray}mole optimize${nc} ${gray}# Optimize system${nc}"
Write-Host " ${gray}mole optimize -Repair${nc} ${gray}# Optimize + all repairs${nc}"
Write-Host " ${gray}mole optimize -Icon${nc} ${gray}# Optimize + rebuild icons${nc}"
Write-Host " ${gray}mole purge${nc} ${gray}# Clean dev artifacts${nc}"
Write-Host "" Write-Host ""
Write-Host " ${green}ENVIRONMENT:${nc}" Write-Host " ${green}ENVIRONMENT:${nc}"
Write-Host "" Write-Host ""
Write-Host " ${cyan}MOLE_DRY_RUN=1${nc} Preview without changes" Write-Host " ${cyan}MOLE_DRY_RUN=1${nc} Preview without changes"
Write-Host " ${cyan}MOLE_DEBUG=1${nc} Enable debug output" Write-Host " ${cyan}MOLE_DEBUG=1${nc} Enable debug output"
Write-Host "" Write-Host ""
Write-Host " ${gray}Run '${nc}mole <command> -ShowHelp${gray}' for command-specific help${nc}" Write-Host " ${gray}Run '${nc}mo <command> --help${gray}' for command-specific help${nc}"
Write-Host "" Write-Host ""
} }
@@ -103,6 +99,12 @@ function Show-MainMenu {
Command = "clean" Command = "clean"
Icon = $script:Icons.Trash Icon = $script:Icons.Trash
} }
@{
Name = "Optimize"
Description = "Optimization & repairs"
Command = "optimize"
Icon = $script:Icons.Arrow
}
@{ @{
Name = "Uninstall" Name = "Uninstall"
Description = "Remove applications" Description = "Remove applications"
@@ -121,12 +123,6 @@ function Show-MainMenu {
Command = "status" Command = "status"
Icon = $script:Icons.Solid Icon = $script:Icons.Solid
} }
@{
Name = "Optimize"
Description = "Optimization & repairs"
Command = "optimize"
Icon = $script:Icons.Arrow
}
@{ @{
Name = "Purge" Name = "Purge"
Description = "Clean dev artifacts" Description = "Clean dev artifacts"
@@ -159,7 +155,7 @@ function Invoke-MoleCommand {
if (-not (Test-Path $scriptPath)) { if (-not (Test-Path $scriptPath)) {
Write-MoleError "Unknown command: $CommandName" Write-MoleError "Unknown command: $CommandName"
Write-Host "" Write-Host ""
Write-Host "Run 'mole -ShowHelp' for available commands" Write-Host "Run 'mo --help' for available commands"
return return
} }
@@ -175,13 +171,13 @@ function Invoke-MoleCommand {
# Remove surrounding quotes if present # Remove surrounding quotes if present
$cleanArg = $arg.Trim("'`"") $cleanArg = $arg.Trim("'`"")
if ($cleanArg -match '^-(\w+)$') { if ($cleanArg -match '^-{1,2}([\w-]+)$') {
# It's a switch parameter (e.g., -DryRun) # It's a switch parameter (e.g., -DryRun or --dry-run)
$paramName = $Matches[1] $paramName = $Matches[1]
$splatParams[$paramName] = $true $splatParams[$paramName] = $true
} }
elseif ($cleanArg -match '^-(\w+)[=:](.+)$') { elseif ($cleanArg -match '^-{1,2}([\w-]+)[=:](.+)$') {
# It's a named parameter with value (e.g., -Name=Value or -Name:Value) # It's a named parameter with value (e.g., --name=value)
$paramName = $Matches[1] $paramName = $Matches[1]
$paramValue = $Matches[2].Trim("'`"") $paramValue = $Matches[2].Trim("'`"")
$splatParams[$paramName] = $paramValue $splatParams[$paramName] = $paramValue