|
| 1 | +# 9. Custom Configuration File Paths |
| 2 | + |
| 3 | +Date: 2025-02-27 |
| 4 | + |
| 5 | +## Status |
| 6 | + |
| 7 | +Proposed |
| 8 | + |
| 9 | +## Context |
| 10 | + |
| 11 | +Currently, the Helm Values Manager uses hardcoded file paths for its configuration and lock files: |
| 12 | +- Configuration file: `helm-values.json` |
| 13 | +- Lock file: `.helm-values.lock` |
| 14 | + |
| 15 | +These paths are defined in the `BaseCommand` class and used across all commands. This approach has several limitations: |
| 16 | + |
| 17 | +1. **Limited Flexibility**: Users cannot manage multiple configurations in the same directory |
| 18 | +2. **Naming Constraints**: Organizations may have specific naming conventions that conflict with our hardcoded names |
| 19 | +3. **Integration Challenges**: Difficult to integrate with existing systems that might have their own file organization |
| 20 | +4. **Location Restrictions**: Configuration files must be in the current working directory |
| 21 | + |
| 22 | +Users have expressed interest in being able to specify custom file paths for their configuration files, which would address these limitations and provide greater flexibility. |
| 23 | + |
| 24 | +## Decision |
| 25 | + |
| 26 | +We will enhance the Helm Values Manager to support custom configuration file paths by: |
| 27 | + |
| 28 | +1. **Adding a `--config-file` option to all commands**: |
| 29 | + ```python |
| 30 | + config_file: str = typer.Option( |
| 31 | + "helm-values.json", |
| 32 | + "--config-file", |
| 33 | + "-c", |
| 34 | + help="Path to the configuration file" |
| 35 | + ) |
| 36 | + ``` |
| 37 | + |
| 38 | +2. **Updating the `BaseCommand` class to accept a config file path**: |
| 39 | + ```python |
| 40 | + def __init__(self, config_file: str = "helm-values.json") -> None: |
| 41 | + """Initialize the base command. |
| 42 | +
|
| 43 | + Args: |
| 44 | + config_file: Path to the configuration file |
| 45 | + """ |
| 46 | + self.config_file = config_file |
| 47 | + self.lock_file = self._generate_lock_file_path(config_file) |
| 48 | + self._lock_fd: Optional[int] = None |
| 49 | + ``` |
| 50 | + |
| 51 | +3. **Generating the lock file name based on the config file path**: |
| 52 | + ```python |
| 53 | + def _generate_lock_file_path(self, config_file: str) -> str: |
| 54 | + """Generate the lock file path based on the config file path. |
| 55 | +
|
| 56 | + Args: |
| 57 | + config_file: Path to the configuration file |
| 58 | +
|
| 59 | + Returns: |
| 60 | + str: Path to the lock file |
| 61 | + """ |
| 62 | + config_path = Path(config_file) |
| 63 | + lock_file = f".{config_path.name}.lock" |
| 64 | + return str(config_path.parent / lock_file) |
| 65 | + ``` |
| 66 | + |
| 67 | +4. **Propagating the config file path to all command instances**: |
| 68 | + ```python |
| 69 | + @app.command() |
| 70 | + def init( |
| 71 | + release_name: str = typer.Option(..., "--release", "-r", help="Name of the Helm release"), |
| 72 | + config_file: str = typer.Option("helm-values.json", "--config-file", "-c", help="Path to the configuration file"), |
| 73 | + ): |
| 74 | + """Initialize a new helm-values configuration.""" |
| 75 | + command = InitCommand(config_file=config_file) |
| 76 | + result = command.execute(release_name=release_name) |
| 77 | + echo(result) |
| 78 | + ``` |
| 79 | + |
| 80 | +## Consequences |
| 81 | + |
| 82 | +### Positive |
| 83 | + |
| 84 | +1. **Increased Flexibility**: Users can manage multiple configurations in the same directory |
| 85 | +2. **Custom Naming**: Organizations can follow their own naming conventions |
| 86 | +3. **Better Integration**: Easier to integrate with existing systems and workflows |
| 87 | +4. **Location Freedom**: Configuration files can be placed in any directory |
| 88 | + |
| 89 | +### Negative |
| 90 | + |
| 91 | +1. **API Change**: All command functions need to be updated to accept the new parameter |
| 92 | +2. **Complexity**: Slightly more complex code to handle different file paths |
| 93 | +3. **Testing**: Additional test cases needed to verify the functionality |
| 94 | +4. **Documentation**: Documentation needs to be updated to reflect the new option |
| 95 | + |
| 96 | +### Neutral |
| 97 | + |
| 98 | +1. **Backward Compatibility**: Default values ensure backward compatibility with existing usage |
| 99 | +2. **Lock File Naming**: Lock files will be named based on the configuration file name |
| 100 | + |
| 101 | +## Implementation Notes |
| 102 | + |
| 103 | +1. The implementation should be backward compatible, using the current hardcoded paths as defaults |
| 104 | +2. All commands should propagate the config file path to their respective command instances |
| 105 | +3. Documentation should be updated to reflect the new option |
| 106 | +4. Tests should be added to verify the functionality with custom file paths |
| 107 | + |
| 108 | +## Related Issues |
| 109 | + |
| 110 | +- GitHub Issue #[TBD]: Support for custom configuration file paths |
0 commit comments