$ show yuk7/wsldl
wsldl is an advanced WSL (Windows Subsystem for Linux) distribution launcher and installer. It provides a CLI tool that manages WSL instances: installing, configuring, running commands, backing up, and cleaning up Linux distributions on Windows. The architecture is a single binary with a command dispatcher pattern, where each subcommand (install, run, config, backup, clean, etc.) is implemented as a separate package with its own 'command.go' and 'help.go' files. The system depends on Windows-specific WSL APIs via the `wsllib-go` and `wslreglib-go` libraries, with platform-conditional stubs for non-Windows builds. The codebase demonstrates strong engineering practices: dependency injection for testability, clear separation of concerns, comprehensive unit tests (over 2000 lines of tests), and a mock-based testing strategy for the WSL API. The CLI supports interactive and non-interactive usage, path translation between Windows and WSL paths, and integration with Windows Terminal and Fluent Terminal.
The LLM identified 5 files worth highlighting for reuse:
Defines the `Command` struct and `RunSubCommand`/`FindCommandFromName` functions that implement a generic subcommand dispatch mechanism. The `Command` struct carries names, visibility, help text, and a run function. The dispatcher matches the first argument to a command name and invokes its run function. This pattern is self-contained and reusable for any CLI tool that needs subcommands with aliases, default commands, and per-distro visibility.
Provides two error types: `DisplayError` (carries show/color/pause flags for CLI rendering) and `ExitCodeError` (requests termination with a specific exit code). Also includes `FormatError`, `MustExecutable`, `Exit`, and colored output helpers (`ErrorRedPrintln`, `StdoutGreenPrintln`). This pattern cleanly separates error semantics from presentation logic and is highly reusable in any CLI application.
Defines `WslLib` and `WslReg` interfaces that abstract the WSL API and registry operations. Also provides `MockWslLib` and `MockWslReg` implementations with per-method function fields, enabling fine-grained mock behavior in tests. The `NewDependencies` function automatically selects mock implementations under `go test` (via `testing.Testing()`). This pattern is a textbook example of interface-based dependency injection for testability and is reusable in any project needing to mock external system APIs.
Provides `CopyFile` with transparent gzip decompression for `.gz`/`.tgz` sources and optional gzip compression for destinations. Also includes `CopyFileAndCompress` that auto-detects compression from destination extension. Additionally contains `DQEscapeString` (shell-safe quoting), `GetWindowsDirectory` (environment-aware), and `IsCurrentDirSpecial` (security check for system directories). This is a self-contained file utility library that solves common cross-platform file handling problems.
Implements HTTP file download with resume support (Range requests), progress bar display via the `progressbar` library, and SHA-256 checksum calculation. Handles partial content, 416 Range Not Satisfiable, and context cancellation. The function returns the SHA-256 hash of the downloaded file. This pattern is reusable in any project that needs to download files with resume capability and integrity verification.