Skip to content

Commit 03c858c

Browse files
committed
feat: Add 'indent' parameter to ConfigurationManager for JSON formatting control
- Added an 'indent' parameter to the ConfigurationManager class, allowing users to specify the JSON indentation level when saving and creating backups. - Updated the 'save' and 'backup' methods to accept the 'indent' parameter and pass it to the underlying JSON template. This enhancement provides users with the flexibility to control the JSON indentation level when using the 'save' and 'backup' methods in the ConfigurationManager class, improving the customization options for JSON formatting.
1 parent 66ae795 commit 03c858c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

jsonpycraft/manager/configuration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(
2222
self,
2323
file_path: str,
2424
initial_data: Optional[JSONMap] = None,
25+
indent: int = 2,
2526
):
2627
"""
2728
Initialize the ConfigurationManager instance.
@@ -37,6 +38,8 @@ def __init__(
3738
self._map_template = JSONMapTemplate(file_path, initial_data=initial_data)
3839
# NOTE: Removed automated loading to avoid a bug where `initial_data` was unintentionally overridden as a result.
3940

41+
self._indent = indent
42+
4043
def load(self) -> None:
4144
"""
4245
Load configuration data from the file.
@@ -55,7 +58,7 @@ def save(self) -> None:
5558
JSONFileErrorHandler: If there is a file-related error accessing the JSON file.
5659
JSONEncodeErrorHandler: If there is an error saving JSON data to the file.
5760
"""
58-
return self._map_template.save_json(self._map_template.data)
61+
return self._map_template.save_json(self._map_template.data, self._indent)
5962

6063
def backup(self) -> None:
6164
"""
@@ -66,7 +69,7 @@ def backup(self) -> None:
6669
JSONDecodeErrorHandler: If there is an error loading JSON data from the file.
6770
JSONEncodeErrorHandler: If there is an error saving JSON data to the file.
6871
"""
69-
return self._map_template.backup_json()
72+
return self._map_template.backup_json(self._indent)
7073

7174
def get_value(self, key: str, default: Optional[Any] = None) -> Any:
7275
"""

0 commit comments

Comments
 (0)