Skip to content

Commit 51334b8

Browse files
committed
refactor: remove command registry pattern
1. Remove command registry implementation 2. Update CLI to use direct command instantiation 3. Add ADR-008 documenting the decision 4. Update ADR index This change simplifies our code by removing unnecessary abstraction. See ADR-008 for detailed rationale.
1 parent 64b2ff4 commit 51334b8

File tree

5 files changed

+81
-147
lines changed

5 files changed

+81
-147
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

docs/ADRs/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ An Architecture Decision Record (ADR) is a document that captures an important a
5555
- **Impact**: Ensures security while maintaining flexibility and traceability
5656
- **Dependencies**: ADR-005
5757

58+
### [ADR-008: Remove Command Registry](008-remove-command-registry.md)
59+
- **Status**: Accepted
60+
- **Context**: Command Registry pattern adds unnecessary complexity
61+
- **Decision**: Remove registry in favor of direct command instantiation
62+
- **Impact**: Simplifies code and aligns better with Typer's design
63+
5864
## ADR Template
5965
For new ADRs, use this template:
6066
```markdown

helm_values_manager/cli.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import typer
44

55
from helm_values_manager.commands.init_command import InitCommand
6-
from helm_values_manager.commands.registry import CommandRegistry
76
from helm_values_manager.utils.logger import HelmLogger
87

98
COMMAND_INFO = "helm values-manager"
@@ -35,10 +34,7 @@ def init(
3534
):
3635
"""Initialize a new values manager configuration."""
3736
try:
38-
# Initialize command registry and register commands
39-
registry = CommandRegistry()
40-
registry.register("init", InitCommand)
41-
command = registry.get_command("init")()
37+
command = InitCommand()
4238
result = command.execute(release_name=release_name)
4339
typer.echo(result)
4440
except Exception as e:

helm_values_manager/commands/registry.py

Lines changed: 0 additions & 71 deletions
This file was deleted.

tests/unit/commands/test_registry.py

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)