Skip to content


Posted on:13 December 2022 at 15:44

TIL that go-flags supports reading flags from environment variables and supports the same option multiple times. I had long been a user of urfave/cli but was not enamoured with the number of dependencies, including a markdown processor, it was injecting into my projects. I switched to pflag, briefly, looking for something a bit more minimalistic, but didn’t find it to be a significant improvement over the standard library’s flag package.

Enter go-flags. I was simply looking to be able to specify the same CLI flag multiple times as I prefer writing -vvv to turn on verbose output instead of --loglevel TRACE. As a bonus I noticed it also supports reading default values from environment variables. And also includes support for maps and callbacks, etc., etc. etc. And yet goweight tells me it only adds an extra 1.7MB to a binary as opposed to 2.8MB for pflag. So I’ll be sticking with go-flags for future projects.