improve readme.md and configs util functions

This commit is contained in:
bluepulsar
2026-01-04 12:52:08 +08:00
parent 1baa0fb954
commit 807785ca7f
6 changed files with 191 additions and 38 deletions
+4 -2
View File
@@ -56,7 +56,7 @@ def load_config(config_name_or_path):
with open(package_config_path, 'r', encoding='utf-8') as f:
return json.load(f)
def list_configs():
def list_config():
"""
List all available JSON configuration files in the configs directory.
@@ -98,7 +98,7 @@ def _format_json_value(value, indent_level=0, indent_str=" "):
# Primitive types (string, number, bool, None)
return json.dumps(value, ensure_ascii=False)
def export_config(config, path="./config/exported_config.json"):
def export_config(config_name = None, path="./config/exported_config.json"):
"""
Export configuration to JSON file with readable formatting.
Arrays/lists are kept on a single line, while nested objects are indented.
@@ -110,6 +110,7 @@ def export_config(config, path="./config/exported_config.json"):
Returns:
The exported config dictionary
"""
config = load_config(config_name)
Path(path).parent.mkdir(parents=True, exist_ok=True)
with open(path, 'w', encoding='utf-8') as f:
@@ -117,5 +118,6 @@ def export_config(config, path="./config/exported_config.json"):
f.write(formatted)
f.write('\n') # Add trailing newline
print(f"Config name: {config_name} exported to {path}")
return config