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

## Configuration

Copy `config.yaml.example` to `~/.config/task-cli/config.yaml` and customize.
The CLI reads configuration from `~/.config/task-cli/config.yaml`.

If the file does not exist, the CLI creates it with default settings:

```yaml
settings:
format: text
max_tasks: 1000
```

You can also copy `config.yaml.example` to `~/.config/task-cli/config.yaml`
and customize it before running commands.
11 changes: 10 additions & 1 deletion task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@
from commands.list import list_tasks
from commands.done import mark_done

DEFAULT_CONFIG = """# Task CLI configuration
settings:
format: text
max_tasks: 1000
"""


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
if not config_path.exists():
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.write_text(DEFAULT_CONFIG)

with open(config_path) as f:
return f.read()

Expand Down
13 changes: 13 additions & 0 deletions test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from commands.add import add_task, validate_description
from commands.done import validate_task_id
from task import DEFAULT_CONFIG, load_config


def test_validate_description():
Expand All @@ -28,3 +29,15 @@ 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 file should be created with sensible defaults."""
monkeypatch.setattr(Path, "home", lambda: tmp_path)

config = load_config()
config_path = tmp_path / ".config" / "task-cli" / "config.yaml"

assert config == DEFAULT_CONFIG
assert config_path.exists()
assert config_path.read_text() == DEFAULT_CONFIG