mirror of
https://github.com/shokinn/hosts-go.git
synced 2025-08-23 16:43:02 +00:00
- Added `internal/core/parser.go` for parsing hosts files, including: - Support for standard entries (IPv4, IPv6, multiple aliases, inline comments) - Handling of comments and disabled entries - Error recovery for malformed lines with warnings - Intelligent formatting with adaptive spacing and column alignment - Backup and atomic write operations for file safety test(parser): Add comprehensive tests for hosts file parsing - Created `tests/parser_test.go` with 54 test cases covering: - Standard entries and comments - Malformed lines and whitespace variations - Round-trip parsing to ensure format preservation - Backup functionality for hosts files docs(progress): Update project progress and next steps - Mark Phase 1 as complete and outline tasks for Phase 2 (TUI implementation) - Highlight completed features and testing coverage
3.3 KiB
3.3 KiB
Product Context: hosts-go
Why This Project Exists
The /etc/hosts
file is a critical system file that maps hostnames to IP addresses, but managing it manually is cumbersome and error-prone. Users currently face several pain points:
- Manual editing: Requires opening
/etc/hosts
in a text editor with sudo privileges - Format preservation: Easy to accidentally break formatting or lose comments
- Entry management: No easy way to temporarily disable entries without deleting them
- DNS resolution: Manual IP address updates when hostnames change
- Organization: No built-in sorting or reordering capabilities
Problems It Solves
- Safe editing: Provides a structured interface that validates changes before writing
- Entry activation: Toggle entries on/off without losing the configuration
- Organization: Sort and reorder entries intuitively
- DNS integration: Automatically resolve hostnames to current IP addresses
- Comment preservation: Maintain documentation alongside entries
- Permission handling: Only request sudo access when actually editing
How It Should Work
Core User Experience
- View mode by default: Browse entries safely without modification risk
- Explicit edit mode: Clear transition to editing with permission request
- Two-pane interface: List view + detail view for efficient navigation
- Keyboard-driven: Fast navigation and actions via keyboard shortcuts
- Visual feedback: Clear indicators for active/inactive entries and changes
Key Workflows
- Browse entries: Launch app, see all current hosts entries with status
- Quick activation: Toggle entries on/off with simple keypress
- Edit existing: Select entry, enter edit mode, modify details
- Add new: Create new hostname mappings with validation
- DNS resolution: Update IP addresses automatically from DNS
- Reorder entries: Drag/move entries to organize logically
User Experience Goals
Immediate Value
- Zero learning curve: Intuitive interface familiar to CLI users
- Safety first: Hard to accidentally break the hosts file
- Speed: Faster than manual editing for common tasks
Long-term Benefits
- Organized hosts: Keep entries structured and documented
- Confidence: Know changes are validated before applied
- Efficiency: Common tasks become single keystrokes
Target Users
- Developers: Managing local development environments
- System administrators: Bulk hosts file management
- Network engineers: Testing connectivity and DNS overrides
- Security professionals: Blocking/redirecting malicious domains
Success Metrics
- Users prefer this tool over manual
/etc/hosts
editing - Reduces hosts file corruption incidents
- Speeds up common host management tasks
- Provides confidence in making changes
Phase 1 Achievements ✅
- Safety foundation: Backup system and atomic writes prevent any data loss
- Format preservation: Intelligent parser maintains user formatting preferences
- Comprehensive validation: IP and hostname validation with clear error messages
- Error resilience: Warning system handles malformed entries gracefully
- Production ready: 54 comprehensive tests covering all edge cases and scenarios
The core value proposition of safe, reliable hosts file management has been fully implemented and validated.