import os from io import StringIO 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", "host": "discourse.forum.com" } } buffer = StringIO() toml.dump(config_data, buffer) 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 print(f"Created sample configuration file: {config_path}") # Create a sample configuration file create_sample_config()