A drop-in replacement for Go's flag package that implements POSIX/GNU-style command-line flags.
pflag is a Go library that replaces the standard flag package, adding support for POSIX/GNU-style command-line flag syntax. It maintains compatibility with existing Go flag code while extending functionality with features like shorthand flags, flag normalization, and subcommand support.
Go developers building command-line applications who need richer flag handling than the standard library provides, especially those requiring POSIX/GNU-style flags or subcommand support.
Developers choose pflag because it offers drop-in compatibility with Go's native flag package while adding familiar POSIX/GNU conventions, shorthand flags, and advanced features like flag normalization and deprecation support.
Drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Can be imported under the name 'flag' to replace Go's native package with no code changes for most uses, as demonstrated in the usage section where only the import path needs adjustment.
Adds support for double-dash long flags (--flag) and single-dash shorthand flags (-f), aligning with common Unix CLI conventions and extending beyond the standard library's capabilities.
Includes features like flag normalization, deprecation messages, hidden flags, and subcommand support via FlagSet, detailed in README sections such as 'Mutating or Normalizing Flag names' and 'Deprecating a flag'.
Provides easy shorthand flags through functions like IntP and BoolVarP, allowing single-letter options that can be combined with dashes, as shown in examples with -abc for boolean flags.
The README admits that pflag does not parse go test's built-in shorthand flags, requiring a workaround like ParseSkippedFlags, which adds complexity for testing workflows.
Introduces a third-party library dependency, which might be undesirable for projects prioritizing minimal vendored code or those with strict dependency policies.
Setting up custom flag name normalization functions requires writing additional code, such as the wordSepNormalizeFunc example, which can be cumbersome for simple use cases.