A Go library that generates command-line flags by parsing struct tags, supporting multiple flag libraries.
sflags is a Go package that generates command-line flags from struct definitions using reflection and struct field tags. It simplifies CLI creation by allowing developers to declaratively define flags, environment variable mappings, and validation rules directly within their configuration structs, reducing boilerplate code and improving maintainability.
Go developers building command-line applications or tools that require configuration via flags, especially those using popular Go flag libraries like flag, pflag, cobra, urfave/cli, or kingpin.
Developers choose sflags for its struct-based declarative approach, which centralizes configuration and reduces repetitive flag parsing code, and for its compatibility with multiple flag libraries, offering flexibility without locking into a single CLI framework.
Generate flags by parsing structures
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows defining flags, descriptions, and environment variables directly in struct tags, centralizing configuration and reducing boilerplate code, as shown in the example with tags like 'desc' and 'env'.
Compatible with popular Go flag libraries like cobra, urfave/cli, and kingpin, offering flexibility without locking into a single framework, evidenced by the support table in the README.
Supports hidden, deprecated, required, and short flags via struct tags, enhancing CLI usability with minimal code, as detailed in the 'Options for flag tag' section.
Automatically maps environment variables to flag values using the 'env' tag, simplifying configuration management without manual parsing.
Feature availability varies by flag library; for example, the standard 'flag' package lacks support for hidden, env, and required flags, limiting its utility in some contexts.
Relies on runtime reflection to parse struct tags, which can introduce performance penalties and runtime errors if tags are misconfigured.
Some planned custom types like enum values, file, and url handling are not yet implemented, as noted in the 'Custom types' section, restricting advanced use cases.