diff --git a/commands/__pycache__/__init__.cpython-314.pyc b/commands/__pycache__/__init__.cpython-314.pyc new file mode 100644 index 0000000..47734d5 Binary files /dev/null and b/commands/__pycache__/__init__.cpython-314.pyc differ diff --git a/commands/__pycache__/add.cpython-314.pyc b/commands/__pycache__/add.cpython-314.pyc new file mode 100644 index 0000000..d890e66 Binary files /dev/null and b/commands/__pycache__/add.cpython-314.pyc differ diff --git a/commands/__pycache__/done.cpython-314.pyc b/commands/__pycache__/done.cpython-314.pyc new file mode 100644 index 0000000..6a8adba Binary files /dev/null and b/commands/__pycache__/done.cpython-314.pyc differ diff --git a/commands/__pycache__/list.cpython-314.pyc b/commands/__pycache__/list.cpython-314.pyc new file mode 100644 index 0000000..dfeb76a Binary files /dev/null and b/commands/__pycache__/list.cpython-314.pyc differ diff --git a/task.py b/task.py index 53cc8ed..0cf7490 100644 --- a/task.py +++ b/task.py @@ -11,11 +11,29 @@ def load_config(): - """Load configuration from file.""" + """Load configuration from file. Returns None if config is missing.""" config_path = Path.home() / ".config" / "task-cli" / "config.yaml" - # NOTE: This will crash if config doesn't exist - known bug for bounty testing - with open(config_path) as f: - return f.read() + if not config_path.exists(): + return None + try: + with open(config_path) as f: + return f.read() + except Exception: + return None + + +def ensure_config(): + """Ensure config file exists with defaults, otherwise create it.""" + config_path = Path.home() / ".config" / "task-cli" / "config.yaml" + if not config_path.exists(): + config_path.parent.mkdir(parents=True, exist_ok=True) + # Copy from example if available + example = Path(__file__).parent / "config.yaml.example" + if example.exists(): + import shutil + shutil.copy(example, config_path) + else: + config_path.write_text("# Default config\n# Add your settings here\n") def main(): @@ -36,10 +54,13 @@ def main(): args = parser.parse_args() if args.command == "add": + ensure_config() add_task(args.description) elif args.command == "list": + ensure_config() list_tasks() elif args.command == "done": + ensure_config() mark_done(args.task_id) else: parser.print_help()