A Go library for parsing command line arguments with extensive features and reflection-based struct tagging.
go-flags is a command line option parser library for Go that extends the functionality of the built-in flag package. It uses reflection and struct tags to define and parse command line options concisely, making it easier to build robust CLI applications with complex option structures.
Go developers building command-line interfaces (CLIs) that require advanced option parsing, such as those needing support for short/long options, multiple option groups, or rich type handling.
Developers choose go-flags over the built-in flag package for its extensive feature set, including struct-based configuration with tags, automatic help generation, and support for slices, maps, and callbacks, which reduces boilerplate code and improves expressiveness.
go command line option parser
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses Go structs with tags to define options, reducing boilerplate code significantly, as shown in the example where Verbose is defined with short and long names.
Handles advanced types like slices, maps, pointers, and callbacks, enabling complex option parsing beyond primitive types, as demonstrated with StringSlice and IntMap in the README.
Supports short/long options, optional arguments, and remaining arguments after --, offering versatile CLI design, including multiple option groups and environment variable integration.
Generates well-formatted help messages automatically from struct tags, improving user experience without manual formatting.
Relies on reflection for parsing, which can introduce performance overhead compared to compile-time approaches and may lead to runtime errors if struct tags are misconfigured.
The struct tag system, while powerful, requires careful attention to syntax and can be error-prone, as seen with multiple tags like choice, env, and value-name in examples.
Primarily designed for option parsing, it may lack built-in features for hierarchical subcommands, which are common in complex CLI applications and might require additional workarounds.