From 0d082006522bdc9775f9da97ae474ae01d6fd6f3 Mon Sep 17 00:00:00 2001 From: Eve Date: Mon, 23 Feb 2026 10:13:41 +0800 Subject: [PATCH] Fix: Create default config when missing instead of crashing - Added ensure_config_exists() function to create default config - Config file is now auto-created at ~/.config/task-cli/config.yaml - User sees helpful message instead of FileNotFoundError Fixes #2 --- task.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/task.py b/task.py index 53cc8ed..1437674 100644 --- a/task.py +++ b/task.py @@ -10,10 +10,39 @@ from commands.done import mark_done +DEFAULT_CONFIG = """# Default configuration for task CLI +# Auto-generated on first run + +# Task storage settings +storage: + format: json + max_tasks: 1000 + +# Display settings +display: + color: true + unicode: true +""" + + +def ensure_config_exists(): + """Ensure config file exists, create default if missing.""" + config_dir = Path.home() / ".config" / "task-cli" + config_path = config_dir / "config.yaml" + + if not config_path.exists(): + # Create config directory if it doesn't exist + config_dir.mkdir(parents=True, exist_ok=True) + # Create default config file + config_path.write_text(DEFAULT_CONFIG) + print(f"Created default config at {config_path}") + + return config_path + + def load_config(): """Load configuration from file.""" - config_path = Path.home() / ".config" / "task-cli" / "config.yaml" - # NOTE: This will crash if config doesn't exist - known bug for bounty testing + config_path = ensure_config_exists() with open(config_path) as f: return f.read()