From 1c757cd243d5b5e84204249eca9d880af3129cf2 Mon Sep 17 00:00:00 2001 From: chengfei-gh Date: Wed, 18 Mar 2026 09:07:14 +0800 Subject: [PATCH] fix: create default config when missing instead of crashing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2 Changes: - load_config() now creates default config.yaml if missing - Creates ~/.config/task-cli/ directory if it doesn't exist - Prints helpful message when creating default config - Uses sensible defaults matching config.yaml.example Previously: FileNotFoundError with ugly stack trace Now: Creates config automatically and continues Tests: - rm ~/.config/task-cli/config.yaml && python task.py list → works - All existing tests still pass --- task.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/task.py b/task.py index 53cc8ed..4b97d16 100644 --- a/task.py +++ b/task.py @@ -10,10 +10,28 @@ from commands.done import mark_done +DEFAULT_CONFIG = """# Default configuration for task CLI +storage: + format: json + max_tasks: 1000 + +display: + color: true + unicode: true +""" + + 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 + """Load configuration from file, creating default if missing.""" + config_dir = Path.home() / ".config" / "task-cli" + config_path = config_dir / "config.yaml" + + if not config_path.exists(): + config_dir.mkdir(parents=True, exist_ok=True) + with open(config_path, "w") as f: + f.write(DEFAULT_CONFIG) + print(f"[task-cli] Created default config at {config_path}") + with open(config_path) as f: return f.read()