Status: Done (2026-03-09)
Priority: Medium
Component: tools/pslib/wsl/lib/commands.ps1, tools/pslib/wsl/lib/manager.ps1
Summary: As a WSL manager user, I want action commands to prompt me for missing arguments so that I don't have to remember the exact CLI syntax to use a command. As a developer, I want a single dispatch path so that CLI and interactive menu don't duplicate routing logic.
Description: This item covers two related refactorings:
The Invoke-WslManager switch block inconsistently handled missing arguments. Some commands passed arguments through, some branched to *Interactive wrappers, and one hard-failed with exit 1. Each action function now owns its argument validation: accept what's given, prompt for what's missing. The *Interactive wrapper functions were merged into their non-Interactive counterparts.
Invoke-WslManager (CLI entry) and Start-InteractiveMode (TUI entry) both contained switch blocks that mapped commands to action functions — violating DRY. Extracted a single Invoke-WslCommand dispatcher that both call.
Nine action functions contained identical interactive distro selection logic (~30 lines each): fetch distros, show numbered table, prompt for number or name, resolve selection. Extracted Select-WslDistro helper, reducing each caller to a 2-line delegation.
Scope decisions:
- Extract
Invoke-WslCommanddispatcher incommands.ps1— single switch block mapping command names to action functions - Move
Invoke-WslManagerandStart-InteractiveModeto newmanager.ps1— orchestration separate from action logic Invoke-WslManagercallsInvoke-WslCommandafter parsing CLI argsStart-InteractiveModemaps menu keys to command names, wrapsInvoke-WslCommandin a single try/catch instead of per-command try/catch boilerplate- Display helpers (
Format-DistroListEntry,Show-WslDistroList) stay incommands.ps1since action functions use them wsl-manager.ps1updated to source bothcommands.ps1andmanager.ps1- Integration tests updated to source
manager.ps1
Acceptance Criteria:
Phase 1 (done):
- All
IsNullOrWhiteSpacechecks removed fromInvoke-WslManagerswitch - Each action function prompts for missing required arguments
-
Invoke-SetupDockerInteractivemerged intoInvoke-SetupDockerand removed -
Invoke-SetupPodmanInteractivemerged intoInvoke-SetupPodmanand removed -
Invoke-SetupProxyInteractivemerged intoInvoke-SetupProxyand removed -
Invoke-SetupUserInteractivemerged intoInvoke-SetupUserand removed -
Invoke-RepairInteropcreated with distro name prompting when not provided -
repair-interopno longer hard-fails withexit 1
Phase 2:
-
Invoke-WslCommanddispatcher created incommands.ps1 -
Invoke-WslManagerandStart-InteractiveModemoved tomanager.ps1 -
Invoke-WslManagerdelegates toInvoke-WslCommand -
Start-InteractiveModedelegates toInvoke-WslCommand(single try/catch, not per-command) -
wsl-manager.ps1sourcesmanager.ps1 - Integration tests source
manager.ps1 - Unit tests updated/split for new file structure
- All existing tests continue to pass
Phase 3:
-
Select-WslDistrohelper extracted incommands.ps1 - 8 action functions refactored to use
Select-WslDistro -
Invoke-TerminateDistrodelegates selection but keeps running-state validation -
Invoke-CreateDistroleft unchanged (different data source) - 11 new unit tests for
Select-WslDistro - All 810 tests pass