Skip to content

Commit 708d88f

Browse files
committed
refactor: consolidate Tool interface and eliminate SOLID principle violations
This comprehensive refactoring addresses multiple SOLID principle violations and consolidates the tool architecture: **SOLID Principle Fixes:** - **Single Responsibility**: Eliminate hardcoded values by extracting constants and configuration providers - **Open/Closed**: Remove switch statements in favor of polymorphic tool implementations - **Interface Segregation**: Consolidate URLProvider and ChecksumProvider into cohesive Tool interface - **Dependency Inversion**: Abstract configuration access through provider interfaces **Key Architectural Changes:** - **Tool Interface Consolidation**: Merge URL generation and checksum verification methods directly into Tool interface, eliminating interface proliferation anti-pattern - **Constants Extraction**: Centralize magic numbers, timeouts, and URLs in constants.go - **Configuration Providers**: Abstract environment variable access through ConfigProvider interfaces - **Platform Abstraction**: Add PlatformMapper for cross-platform binary handling - **Path Resolution**: Implement PathResolver utilities for consistent tool path management - **Error Handling**: Standardize error types and wrapping across all tools **Tool Implementation Updates:** - **Maven/Mvnd**: Add GetChecksum methods with Apache archive SHA512 verification - **Node.js**: Enhance SHASUMS256.txt parsing with better error handling - **Java**: Integrate Foojay Disco API checksum verification - **Go**: Maintain existing go.dev API integration - **All Tools**: Implement unified URL generation and checksum verification methods **Command System Simplification:** - Replace tool-specific switch statements with polymorphic manager methods - Consolidate search, validation, and info commands through unified Tool interface - Eliminate 300+ lines of duplicated tool-specific command handling code **Download System Integration:** - Update DownloadConfig to use Tool interface directly for checksum verification - Remove dependency on separate ChecksumRegistry and URLProvider registrations - Simplify verification flow through direct tool method calls **Benefits:** - **Maintainability**: Related functionality stays together in cohesive interfaces - **Extensibility**: New tools require zero changes to existing command/download code - **Testability**: Each tool's functionality can be tested independently - **Consistency**: Standardized patterns across all tool implementations - **Simplicity**: Fewer abstractions, clearer design, easier to understand This refactoring transforms the codebase from an anti-pattern heavy design with interface proliferation and switch statement violations into a clean, SOLID-compliant architecture with proper separation of concerns.
1 parent acc1fd4 commit 708d88f

20 files changed

+2140
-1212
lines changed

cmd/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ For more information, visit: https://github.com/gnodet/mvx`,
5555
func Execute() error {
5656
// Auto-setup tools and environment before executing any command
5757
if err := autoSetupEnvironment(); err != nil {
58-
// Don't fail completely if auto-setup fails, but warn the user
59-
printVerbose("Auto-setup failed: %v", err)
58+
// If auto-setup fails, we should fail the command execution
59+
// This prevents commands from running with missing tools
60+
return fmt.Errorf("auto-setup failed: %w", err)
6061
}
6162

6263
// Add dynamic custom commands before execution

0 commit comments

Comments
 (0)