The context use command writes to ~/.iggy/.active_context via tokio::fs::write, which fails if the ~/.iggy/ directory hasn't been created yet.
The recently added context create command handles this by calling ensure_iggy_home_exists() before writing, but the existing write_active_context() and write_contexts() methods in ContextReaderWriter don't do this.
Steps to reproduce:
- Remove
~/.iggy/ if it exists
- Run
iggy context use default
- Observe a write error because the directory is missing
Fix would be to call ensure_iggy_home_exists() inside write_active_context() and write_contexts() so all write paths handle a fresh system.
Please wait before #2998 merges to work on this.