go-flags reads struct field tags, so -vvv becomes a slice of three true values
go command line option parser
At a glance
- What is it?
- jessevdk/go-flags is a Go command line option parser that uses structs, reflection and struct field tags in place of flag.Int calls. The README is short, and the source files hint at more than it documents.
- Who is it for?
- Choose go-flags if you want to declare options as a Go struct with short, long, description and required tags, and you want grouped options, callbacks and a generated help message without hand-writing them. Stay with the standard flag package if you want zero dependencies and a flat list of options.
- Can I use it commercially?
- Yes. BSD-3-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 46 days ago.
- What is it written in?
- Mainly Go, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- jessevdk/go-flags2,693 ★ · -1
| Repository | 2026-10-08 | 2026-11-25 |
|---|---|---|
| jessevdk/go-flags | 2.7k | 2.7k |
-1 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Options are declared as struct fields, and the tags carry the flag names
go-flags does not ask you to register each option with a function call. You write a struct, put short, long and description tags on the fields, and the package reads them through reflection. The project's smallest example is one field:
type Options struct {
Verbose []bool `short:"v" long:"verbose" description:"Show verbose debug information"`
}That defines -v and --verbose in one place. The package's own description calls this a very simple and concise specification of application options, and it is the main reason to pick it over the builtin flag package, which it resembles in functionality while offering more options.
Because the declaration is a struct, the same type that holds the parsed values also documents the options. A reader of the code sees every flag name next to its Go type.
Repeating a short flag appends to a slice, so -vvv yields three true values
A field of type []bool changes what the parser does with repetition. Each time -v or --verbose appears, a true value is appended to the Verbose field. Typing -vvv gives {[true, true, true]}, so the length of the slice is the verbosity level.
The README's longer example documents this in a comment: a slice of bool appends true each time the option is encountered, and it can be set multiple times, like -vvv. The same behavior is listed as supporting the same option multiple times, stored in a slice or with the last occurrence counting.
The tradeoff is a type that is less obvious than a plain bool. Code that reads the flag has to check len(opts.Verbose) instead of testing a boolean, and a reader unfamiliar with the idiom has to be told why a verbose flag is a slice.
Types are converted for you, and the example shows uint, callbacks and required
The longer example in the README declares a struct with several fields. Verbose is the slice above. Offset is a uint with the long name offset, an example of automatic marshalling to the desired type. Call is a func(string) tagged short:"c", a callback that is called each time the option is found. Name is a string with short n and long name, marked required:"true".
The feature list backs this up: all primitive Go types are supported (string, int{8..64}, uint{8..64}, float), as well as maps and function callbacks.
The README's example is cut off after the required flag, so the rest of it is not shown there. For the remaining tags and the full parse call, the README sends you to the godocs at godoc.org/github.com/jessevdk/go-flags. A new user will need that page open to see how the parser is actually invoked.
The argument syntaxes it accepts and the optional behaviors it can switch on
The listed features cover how users type options. Short names (-v) and long names (--verbose) both work. Options may take no argument, like a bool, or an argument of another type. There are options with optional arguments and default values.
On the argument form, the README lists -I/usr/include, -I=/usr/include and -I /usr/include as accepted specifications of the same option. Multiple short options can be combined, as in -aux.
Two behaviors are marked optional: passing remaining command line arguments after -- and ignoring unknown command line options. Since both are optional, the default is to treat an unknown option as an error. If you wrap another tool and want to forward flags you do not recognize, that is something to turn on.
The README does not say how to turn either one on. The godocs are where the parser's options live.
Option groups and namespaces keep a large flag set organized
go-flags supports multiple option groups, each containing a set of options, and namespaces for nested option groups. For a program with many flags, that gives a way to split them into sections, such as one group per subsystem, without one giant struct.
The feature list also includes generating and printing a well-formatted help message. The help.go file sits at the top of the repository next to group.go, option.go, parser.go and command.go, which is where the corresponding code lives. The README does not describe the help format, so run a small program to see how the output looks.
The examples directory has examples/main.go, examples/add.go and examples/rm.go, which suggests a program with add and rm commands. The README never mentions subcommands in its feature list, so read those files before relying on them.
Source files beyond the README: completion, ini, man pages and terminal width
The top-level file list is larger than the README's feature list. It includes completion.go, ini.go, man.go, closest.go and several termsize files, among them termsize_windows.go, along with optstyle_windows.go and optstyle_other.go. The examples directory holds examples/bash-completion and examples/zsh-completion.
Those names point at shell completion, INI file handling, man page generation, suggestions for a misspelled option and terminal size detection. The README documents none of them, so the file names are all the evidence here, and you should read the code or the godocs before planning around any of them.
There are also tests for most files, including parser_test.go, group_test.go and help_test.go, and a check_crosscompile.sh script. The repository carries an AI_POLICY.md and a CONTRIBUTING.md at the top level.
Maintenance: BSD-3-Clause, last push 2026-10-10, three tags on one day
The repository is not archived. Its last push was on 2026-10-10. The license is BSD-3-Clause. The three most recent tags, v1.5.0, v1.6.0 and v1.6.1, were all created on 2024-06-15, within a few hours of each other, so the version history for that date is a burst, not a gradual progression.
The module is github.com/jessevdk/go-flags and go.mod declares go 1.24. Its requirements are github.com/sergi/go-diff v1.3.1 and golang.org/x/sys v0.21.0. If your build targets an older Go toolchain, check this line first, because the module will not declare compatibility below what go.mod states.
The README has no installation section and no go get line, so the only stated location is the module path and the godocs.
Editorial conclusion
Choose go-flags if you want to declare options as a Go struct with short, long, description and required tags, and you want grouped options, callbacks and a generated help message without hand-writing them. Stay with the standard flag package if you want zero dependencies and a flat list of options. Before adopting it, check go.mod: it declares go 1.24 and requires golang.org/x/sys and sergi/go-diff, and the latest tagged release is v1.6.1 from 2024-06-15.
Frequently asked questions
What is the flag package in Go and how does go-flags differ?
The standard flag package is Go's builtin option parser. go-flags offers similar functionality with more options, and it uses structs, reflection and struct field tags to specify them.
Does go-flags support both short and long options?
Yes. It supports short names such as -v and long names such as --verbose, and also combined short options like -aux.
Where is the documentation for go-flags?
The README points to the godocs at godoc.org/github.com/jessevdk/go-flags for more information.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/jessevdk-go-flags)Star history chart for your README
[](https://hysenlabs.com/projects/jessevdk-go-flags)Was this useful?