Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions task.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,30 @@
from commands.done import mark_done


def load_config():
DEFAULT_CONFIG = """# Task CLI configuration

storage:
format: json
max_tasks: 1000

display:
color: true
unicode: true
"""


def load_config(config_path=None):
"""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
with open(config_path) as f:
return f.read()
if config_path is None:
config_path = Path.home() / ".config" / "task-cli" / "config.yaml"
else:
config_path = Path(config_path)

if not config_path.exists():
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.write_text(DEFAULT_CONFIG)

return config_path.read_text()


def main():
Expand All @@ -35,6 +53,8 @@ def main():

args = parser.parse_args()

load_config()

if args.command == "add":
add_task(args.description)
elif args.command == "list":
Expand Down
18 changes: 18 additions & 0 deletions test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import pytest
from pathlib import Path
from task import DEFAULT_CONFIG, load_config
from commands.add import add_task, validate_description
from commands.done import validate_task_id

Expand All @@ -28,3 +29,20 @@ def test_validate_task_id():

with pytest.raises(ValueError):
validate_task_id(tasks, 99)


def test_load_config_creates_default_when_missing(tmp_path):
"""Missing config file should be created with defaults."""
config_path = tmp_path / ".config" / "task-cli" / "config.yaml"

assert load_config(config_path) == DEFAULT_CONFIG
assert config_path.read_text() == DEFAULT_CONFIG


def test_load_config_reads_existing_file(tmp_path):
"""Existing config file should be returned unchanged."""
config_path = tmp_path / ".config" / "task-cli" / "config.yaml"
config_path.parent.mkdir(parents=True)
config_path.write_text("display:\n color: false\n")

assert load_config(config_path) == "display:\n color: false\n"