Skip to content

Commit 436e043

Browse files
committed
refactor: simplify init command and improve test structure
1. Removed config_file option from init command 2. Converted test_base_command.py from class-based to function-based tests 3. Renamed TestCommand to DummyCommand in test_registry.py to avoid warnings 4. Updated test assertions to match new command output
1 parent da591fc commit 436e043

File tree

5 files changed

+303
-153
lines changed

5 files changed

+303
-153
lines changed

helm_values_manager/cli.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,9 @@ def main(ctx: typer.Context):
2828
@app.command()
2929
def init(
3030
release_name: str = typer.Option(..., "--release", "-r", help="Name of the Helm release"),
31-
config_file: str = typer.Option(
32-
"values-manager.yaml",
33-
"--config",
34-
"-c",
35-
help="Path to the values manager configuration file",
36-
),
3731
):
3832
"""Initialize a new values manager configuration."""
39-
typer.echo(f"Initializing values manager with config file: {config_file}, for the release: {release_name}.")
33+
typer.echo(f"Initializing values manager for the release: {release_name}.")
4034
# TODO: Implement initialization logic
4135

4236

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""Command registry for managing helm-values commands."""
2+
3+
from typing import Dict, Type
4+
5+
from helm_values_manager.commands.base_command import BaseCommand
6+
7+
8+
class CommandRegistry:
9+
"""Registry for managing helm-values commands.
10+
11+
This class provides a central registry for all available commands in the
12+
helm-values plugin. It handles command registration and lookup.
13+
"""
14+
15+
_instance = None
16+
_commands: Dict[str, Type[BaseCommand]] = {}
17+
18+
def __new__(cls):
19+
"""Create a new singleton instance of CommandRegistry."""
20+
if cls._instance is None:
21+
cls._instance = super(CommandRegistry, cls).__new__(cls)
22+
return cls._instance
23+
24+
@classmethod
25+
def register(cls, name: str, command_class: Type[BaseCommand]) -> None:
26+
"""Register a new command.
27+
28+
Args:
29+
name: The name of the command
30+
command_class: The command class to register
31+
32+
Raises:
33+
ValueError: If a command with the same name already exists
34+
"""
35+
if name in cls._commands:
36+
raise ValueError(f"Command {name} already registered")
37+
cls._commands[name] = command_class
38+
39+
@classmethod
40+
def get_command(cls, name: str) -> Type[BaseCommand]:
41+
"""Get a command by name.
42+
43+
Args:
44+
name: The name of the command to get
45+
46+
Returns:
47+
The command class
48+
49+
Raises:
50+
KeyError: If the command is not found
51+
"""
52+
if name not in cls._commands:
53+
raise KeyError(f"Command {name} not found")
54+
return cls._commands[name]
55+
56+
@classmethod
57+
def list_commands(cls) -> Dict[str, Type[BaseCommand]]:
58+
"""List all registered commands.
59+
60+
Returns:
61+
A dictionary mapping command names to command classes
62+
"""
63+
return cls._commands.copy()
64+
65+
@classmethod
66+
def clear(cls) -> None:
67+
"""Clear all registered commands.
68+
69+
This is primarily used for testing.
70+
"""
71+
cls._commands.clear()

tests/integration/test_cli_integration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ def test_init_help_command(plugin_install):
7070

7171
assert returncode == 0
7272
assert "Initialize a new values manager configuration" in stdout
73-
assert "--config" in stdout
74-
assert "-c" in stdout
73+
assert "--release" in stdout
74+
assert "-r" in stdout
7575

7676

7777
def test_init_command(plugin_install, tmp_path):
78-
"""Test that the init command works with default config file."""
78+
"""Test that the init command works."""
7979
stdout, stderr, returncode = run_helm_command(["values-manager", "init", "-r", "test"])
8080

8181
assert returncode == 0
82-
assert "Initializing values manager with config file: values-manager.yaml, for the release: test." in stdout
82+
assert "Initializing values manager for the release: test." in stdout

0 commit comments

Comments
 (0)