How tomnomnom/anew works
Project type and purpose
• Type: CLI tool written in Go
• Purpose: Read lines from stdin, append only non-duplicate lines to a target file, and echo those new lines to stdout.
Main components
a. CLI Interface / Flag Parser
• Accepts positional argument (target filename)
• Flags: -d (dry-run), -q (quiet)
b. File Loader
• Opens and reads the existing target file into an in-memory set (hash)
c. Input Stream Reader
• Reads lines from stdin one at a time
d. Duplicate Detector
• Checks each input line against the in-memory set
• If not present, forwards line to both File Appender and Output Writer
e. File Appender
• Opens the file in append mode and writes new lines (skipped if dry-run or quiet)
f. Output Writer
• Writes new lines to stdout (skipped if quiet)
g. Packaging / Release Script
• script/release: shell script that builds cross-compiled binaries and prepares GitHub releases
Relationships & Data Flow
1. stdin → Input Stream Reader
2. CLI Interface → File Loader (to get existing lines)
3. CLI Interface → Duplicate Detector (flag settings)
4. Input Stream Reader → Duplicate Detector
5. Duplicate Detector → File Appender (conditionally)
6. Duplicate Detector → Output Writer (conditionally)
7. Packaging Script → Go Compiler & GitHub Releases
Architectural Patterns & Design Principles
• Linear streaming pipeline: input → process → output
• Use of in-memory hash set for O(1) membership checks
• Clear separation of concerns: parsing, I/O, processing
• Minimal external dependencies: only Go standard library
Technology Stack & Frameworks
• Go runtime (golang)
• Standard library modules: flag, bufio, os, fmt
• Shell script for release automation