I Wrote A CLI Tool Instead Of Doing The Thing
I needed to rename 12 files. Instead, I wrote a general-purpose file renaming CLI tool in Go with regex support, dry-run mode, and colorized output.
The Tool
package main
import (
"flag"
"fmt"
"regexp"
// 47 more imports
)
func main() {
dryRun := flag.Bool("dry-run", false, "preview changes")
pattern := flag.String("pattern", "", "regex pattern")
recursive := flag.Bool("r", false, "recursive mode")
verbose := flag.Bool("v", false, "verbose output")
colors := flag.Bool("colors", true, "colorized output")
// 12 more flags
// 400 lines of immaculately structured code
}
The Task
# What I actually needed to do
for f in *.jpeg; do mv "$f" "${f%.jpeg}.jpg"; done
Time Investment
| Activity | Time |
|---|---|
| Writing the CLI tool | 4 hours |
| Adding tests | 1 hour |
| Debating flag names | 45 minutes |
| Actually renaming the files | 5 minutes |
| Convincing myself it was worth it | ongoing |
Was It Worth It?
The tool now lives in a private repo I’ll never open again. But it compiles to a single binary, so that’s something.
Next week I need to delete 3 log files. Time to write a log rotation daemon.