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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ python -m pytest test_task.py

## Configuration

Copy `config.yaml.example` to `~/.config/task-cli/config.yaml` and customize.
On first config load, the CLI creates `~/.config/task-cli/config.yaml` with default settings if it is missing. To customize the defaults manually, copy `config.yaml.example` to that path and edit it.
26 changes: 22 additions & 4 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


DEFAULT_CONFIG = """# Default configuration for task CLI
storage:
format: json
max_tasks: 1000

display:
color: true
unicode: true
"""


def get_config_path():
"""Return the default configuration file path."""
return Path.home() / ".config" / "task-cli" / "config.yaml"


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
with open(config_path) as f:
return f.read()
config_path = get_config_path()
if not config_path.exists():
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.write_text(DEFAULT_CONFIG, encoding="utf-8")

return config_path.read_text(encoding="utf-8")


def main():
Expand Down
17 changes: 15 additions & 2 deletions test_task.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Basic tests for task CLI."""

import json
import pytest
from pathlib import Path

import task
from commands.add import add_task, validate_description
from commands.done import validate_task_id

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

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


def test_load_config_creates_default_when_missing(tmp_path, monkeypatch):
"""Missing config should be initialized instead of crashing."""
monkeypatch.setattr(task.Path, "home", staticmethod(lambda: tmp_path))
config_path = tmp_path / ".config" / "task-cli" / "config.yaml"

assert not config_path.exists()

config = task.load_config()

assert config == task.DEFAULT_CONFIG
assert config_path.read_text(encoding="utf-8") == task.DEFAULT_CONFIG