💾 Archived View for ser1.net › post › claptrap.gmi captured on 2024-03-21 at 15:02:23. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-07-22)

🚧 View Differences

-=-=-=-=-=-=-

--------------------------------------------------------------------------------

title: "claptrap: a Go flags library. Very small, much features! No dependencies & getoptish." date: 2022-09-28T21:34:00Z updated: 2022-10-17T18:41:00-05:00 tags: ["golang", "library", "flags"]

--------------------------------------------------------------------------------

Note

Turn on dark mode: upper right, little sun-looking thing. Code blocks in this theme look hideous in light mode, and I simply haven't been able to work up the enthusiasm to learn enough scss to figure out how to fix it. I could change themes, I guess, but that affects the whole site, and... just use the dark theme for now, ok? Thanks.

--------------------------------------------------------------------------------

claptrap opts lib: very small, much features, getoptish

https://sr.ht/~ser/claptrap/

Every few months, when I start a new CLI, I spend a good amount of time looking around for a flags library. For trivial programs, the stdlib `flag` library is OK, but it breaks `getopt` arguments style, the undisputed most popular arguments standard for POSIXy OSes, in the world. And there are a wealth of alternative flags libraries available, some quite good, but I am inevitably unsatisfied with them for usually one of three reasons:

Over time, I'd built up some tooling to evaluate lib tools; I've posted that, and the analysis, here[1], and I focused this time on clapper[2], which seemed to fit the bill. There were a couple of small features I wanted, and I sent in a couple of patches, but after one particularly engaging hacking session I ended up with a drastic rewrite that maintained and expanded the feature set while preserving the small size and general `getopts` compatability. At this point, it was a different library, so I rebranded it and Claptrap was born.

1: https://hg.sr.ht/~ser/flags-libs-analysis

2: https://github.com/thatisuday/clapper

Claptrap is a small but powerful Go package to parse command-line arguments

3: http://man7.org/linux/man-pages/man3/getopt.3.html

And it's 455 lines of code, and **0** dependencies.