A Go library for parsing command-line arguments by defining a struct, supporting flags, environment variables, and subcommands.
go-arg is a command-line argument parsing library for Go that uses struct definitions to declare and parse arguments. It simplifies CLI development by leveraging Go's type system, eliminating the need for separate configuration APIs and allowing developers to define arguments directly as struct fields with tags.
Go developers building command-line tools, from simple scripts to complex applications with subcommands, who prefer a declarative, type-safe approach to argument handling.
Developers choose go-arg for its intuitive struct-based API that reduces boilerplate, integrates seamlessly with Go's type system, and supports advanced features like environment variables, subcommands, and custom validation without sacrificing simplicity.
Struct-based argument parsing in Go
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 to define arguments, reducing boilerplate and leveraging type safety, as shown in simple examples like `arg.MustParse(&args)` for quick setup.
Seamlessly sources arguments from environment variables with command-line precedence, demonstrated by tags like `arg:"env"` and configurable prefixes for flexible configuration.
Enables complex CLI architectures with subcommands using pointer fields tagged with `subcommand:`, illustrated in the git-like checkout/commit/push example.
Supports custom types via `encoding.TextUnmarshaler`, allowing developers to define bespoke parsing logic, as seen in the NameDotName implementation example.
Configuration through struct tags can become cluttered and error-prone, especially with multiple options like `arg:"--count,env:NUM_WORKERS"` and separate `help` tags.
Lacks built-in support for common CLI enhancements such as automatic shell completion, argument aliasing beyond short/long forms, or interactive prompts.
Relies on Go's reflection for parsing, which may introduce performance overhead compared to code-generated parsers in high-frequency CLI tools.