All posts

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

ActivityTime
Writing the CLI tool4 hours
Adding tests1 hour
Debating flag names45 minutes
Actually renaming the files5 minutes
Convincing myself it was worth itongoing

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.