refactor: Split cmd/ god package into sub-packages (phase 1)#314
refactor: Split cmd/ god package into sub-packages (phase 1)#314ajitpratap0 merged 3 commits intomainfrom
Conversation
|
Claude finished @ajitpratap0's task —— View job Code Review: Package Refactoring (Phase 1) ✅Review Tasks:
🎯 Overall Assessment: EXCELLENTThis is a well-executed refactoring that successfully addresses the architectural issue of a 13.7K LOC god package. The changes maintain backward compatibility while improving code organization. ✅ StrengthsArchitecture & Organization
Code Quality
Security
🔍 Detailed Review by Filecmd/gosqlx/cmd/root.go (9 additions)
cmd/gosqlx/internal/actioncmd/action.go (17 additions, 35 deletions)
cmd/gosqlx/internal/cmdutil/ (358 new lines)
cmd/gosqlx/internal/lspcmd/lsp.go (13 additions, 15 deletions)
cmd/gosqlx/internal/optimizecmd/optimize.go (33 additions, 35 deletions)
🚀 Performance Impact: POSITIVE
🔒 Security Analysis: STRONGThe refactored security validation in // Multi-layered security approach (lines 169-234)
1. Path traversal prevention ✅
2. Symlink resolution & validation ✅
3. File size enforcement ✅
4. Extension validation ✅
5. Permission verification ✅📋 Test Coverage Considerations
🎯 Minor Suggestions (Non-blocking)
🏁 ConclusionThis refactoring exemplifies best practices:
Recommendation: APPROVE - This is production-ready code that successfully addresses the architectural debt while maintaining system reliability. |
|
Claude finished @ajitpratap0's task —— View job Code Review: Package Refactoring (Phase 1) ✅Review Tasks:
🎯 Overall Assessment: EXCELLENTThis is a well-executed refactoring that successfully addresses the architectural issue of a 13.7K LOC god package. The changes maintain backward compatibility while improving code organization and security. ✅ StrengthsArchitecture & Organization
Code Quality
Security
🔍 Detailed Review by File
|
|
Claude finished @ajitpratap0's task —— View job Code Review: Package Refactoring (Phase 1) ✅Review Tasks:
🎯 Overall Assessment: EXCELLENTThis is a well-executed refactoring that successfully addresses the architectural issue of a 13.7K LOC god package. The changes maintain backward compatibility while improving code organization and security. ✅ StrengthsArchitecture & Organization
Code Quality
Security
🔍 Detailed Review by File
|
|
Claude finished @ajitpratap0's task —— View job Code Review: Package Refactoring (Phase 1) ✅Review Tasks:
🎯 Overall Assessment: EXCELLENTThis is a well-executed refactoring that successfully addresses the architectural issue of a 13.7K LOC god package. The changes maintain backward compatibility while improving code organization and security. ✅ StrengthsArchitecture & Organization
Code Quality
Security
🔍 Detailed Review by File
|
…timize into sub-packages Extract the most independent subcommands (lsp, action, optimize) from the 13.7K LOC cmd/gosqlx/cmd/ god package into dedicated sub-packages under cmd/gosqlx/internal/: - cmd/gosqlx/internal/lspcmd/ — LSP server command (zero deps on cmd pkg) - cmd/gosqlx/internal/actioncmd/ — GitHub Actions CI command (self-contained) - cmd/gosqlx/internal/optimizecmd/ — SQL optimization command - cmd/gosqlx/internal/cmdutil/ — shared utilities (stdin, input detection, flags) Each sub-package exports a NewCmd() constructor returning *cobra.Command. Root command registers them via rootCmd.AddCommand(). Remaining commands (validate, format, analyze, parse, lint, config, watch) stay in cmd/gosqlx/cmd/ for now due to heavy cross-dependencies between their types (ValidatorOptions, CLIFormatterOptions, etc.). These can be split in follow-up PRs once shared types are extracted to cmdutil. No behavior changes — pure structural refactor.
- Port lintFile rules-filtering logic from PR #312 (allRules + selection) - Move package-level mutable vars into actionFlags struct - Replace *string pointers in optimizecmd with cmdutil.RootFlags - Fix IsValidSQLFileExtension('') returning true - Add tests for cmdutil package (IsValidSQLFileExtension, ExpandDirectory, LooksLikeSQL)
2ef6502 to
19a8cd7
Compare
|
Claude finished @ajitpratap0's task —— View job Code Review: Package Refactoring (Phase 1) ✅Review Tasks:
🎯 Overall Assessment: EXCELLENTThis is a well-executed refactoring that successfully addresses the architectural issue of a 13.7K LOC god package. The changes maintain backward compatibility while improving code organization and security. ✅ StrengthsArchitecture & Organization
Code Quality
Security
🔍 Detailed Review by File
|
Addresses architect finding: cmd/gosqlx/cmd/ was 13.7K LOC in one flat package.
Phase 1: Extract independent commands
Extracted the 3 most independent subcommands into dedicated sub-packages:
cmd/gosqlx/internal/lspcmd/— LSP server (zero deps on cmd pkg)cmd/gosqlx/internal/actioncmd/— GitHub Actions CI (self-contained)cmd/gosqlx/internal/optimizecmd/— SQL optimizationcmd/gosqlx/internal/cmdutil/— shared utilities (stdin, input detection, flags)Each sub-package exports
NewCmd()returning*cobra.Command.What remains (phase 2)
The remaining commands (validate, format, analyze, parse, lint, config, watch) stay in
cmd/gosqlx/cmd/due to heavy cross-dependencies between types likeValidatorOptions,CLIFormatterOptions,Formatter,Validator, etc.Verification
go build ./...✅go test ./... -short✅gofmt -s -w .✅