|
| 1 | +# 8. Remove Command Registry Pattern |
| 2 | + |
| 3 | +Date: 2025-02-26 |
| 4 | + |
| 5 | +## Status |
| 6 | + |
| 7 | +Accepted |
| 8 | + |
| 9 | +## Context |
| 10 | + |
| 11 | +We initially implemented a Command Registry pattern to manage and discover commands in our Helm plugin. The registry was designed to: |
| 12 | +- Register commands with unique names |
| 13 | +- Retrieve command instances by name |
| 14 | +- Potentially support future features like plugins, middleware, and dynamic command loading |
| 15 | + |
| 16 | +However, our current implementation shows that: |
| 17 | +1. Commands are statically defined in CLI functions using Typer |
| 18 | +2. Each CLI function directly knows which command to instantiate |
| 19 | +3. We don't have requirements for: |
| 20 | + - Plugin system or third-party extensions |
| 21 | + - Dynamic command loading/discovery |
| 22 | + - Command aliasing or middleware |
| 23 | + - Runtime command configuration |
| 24 | + |
| 25 | +The registry adds an unnecessary layer of indirection: |
| 26 | +```python |
| 27 | +# Current approach with registry |
| 28 | +registry = CommandRegistry() |
| 29 | +registry.register("init", InitCommand) |
| 30 | +command = registry.get_command("init")() |
| 31 | + |
| 32 | +# Simplified to |
| 33 | +command = InitCommand() |
| 34 | +``` |
| 35 | + |
| 36 | +## Decision |
| 37 | + |
| 38 | +We will remove the Command Registry pattern and use direct command instantiation because: |
| 39 | +1. It simplifies the code by removing unnecessary abstraction |
| 40 | +2. It follows YAGNI (You Ain't Gonna Need It) principle |
| 41 | +3. Our commands are fixed and well-defined as part of the Helm plugin |
| 42 | +4. Typer handles CLI command registration and discovery |
| 43 | +5. We don't have current or planned requirements that would benefit from a registry |
| 44 | + |
| 45 | +## Consequences |
| 46 | + |
| 47 | +### Positive |
| 48 | +1. Simpler, more maintainable code |
| 49 | +2. Less indirection and complexity |
| 50 | +3. Easier to understand command flow |
| 51 | +4. Reduced testing surface |
| 52 | +5. Better alignment with Typer's design |
| 53 | + |
| 54 | +### Negative |
| 55 | +1. If we need these features in the future, we'll need to: |
| 56 | + - Reimplement the registry pattern |
| 57 | + - Update all command instantiation points |
| 58 | + - Add command discovery mechanism |
| 59 | + |
| 60 | +### Neutral |
| 61 | +1. Command implementation and interface remain unchanged |
| 62 | +2. CLI functionality remains the same |
| 63 | +3. User experience is unaffected |
| 64 | + |
| 65 | +## Future Considerations |
| 66 | + |
| 67 | +If we need registry features in the future, we should consider: |
| 68 | +1. Plugin system requirements |
| 69 | +2. Command discovery needs |
| 70 | +3. Middleware requirements |
| 71 | +4. Integration with Helm plugin system |
| 72 | + |
| 73 | +## Related |
| 74 | +- [ADR-001] Initial Architecture Decision |
0 commit comments