lunduke-cli/config/create_config.py

33 lines
872 B
Python
Raw Normal View History

2025-04-12 17:16:27 +00:00
import os
from io import StringIO
2025-04-12 17:16:27 +00:00
import toml
def create_sample_config(config_path="config.toml"):
"""Create a sample configuration file if it doesn't exist"""
if os.path.exists(config_path):
print(f"Configuration file already exists: {config_path}")
return
config_data = {
"user": {
"username": "joe_doakes"
},
"api": {
"key_file": "cli_key.txt",
2025-04-12 17:16:27 +00:00
"host": "discourse.forum.com"
}
}
buffer = StringIO()
toml.dump(config_data, buffer)
2025-04-12 17:16:27 +00:00
with open(config_path, "w") as config_file:
config_file.write(buffer.getvalue())
# with open(config_path, "w") as config_file:
# toml.dump(config_data, config_file) # type: ignore
2025-04-12 17:16:27 +00:00
print(f"Created sample configuration file: {config_path}")
# Create a sample configuration file
create_sample_config()