aboutsummaryrefslogtreecommitdiff
path: root/flag.go
AgeCommit message (Collapse)Author
2026-01-10Fix for Go 1.24Pascal Terjan
Go 1.24 no longer allows dynamic format string.
2025-10-05Show 'correct' explicit bool value syntax in helpAli Mohammad Pur
2025-09-02Merge pull request #448 from thaJeztah/fix_go_versionv1.0.10Tomas Aschan
remove uses of errors.Is, which requires go1.13, move go1.16/go1.21 tests to separate file
2025-09-01remove uses of errors.Is, which requires go1.13Sebastiaan van Stijn
Commit 1bf832c6fec8a35a8c1d61e5fb14f5ce404197ef introduced the use of `errors.Is`, which was added in [go1.13], but the `go.mod` was not updated to reflect this, causing compile failures on go1.12: docker run -it --rm -v ./:/pflag -w /pflag golang:1.12 sh -c 'go test -v ./...' # github.com/spf13/pflag [github.com/spf13/pflag.test] ./flag.go:1190:7: undefined: errors.Is ./flag.go:1219:7: undefined: errors.Is ./bool_func_test.go:86:28: cannot use stdFSet (type *flag.FlagSet) as type BoolFuncFlagSet in argument to runCase: *flag.FlagSet does not implement BoolFuncFlagSet (missing BoolFunc method) ... As the error that is tested will not be wrapped, we can omit the `errors.Is`, and instead continue doing a straight comparison. [go1.13]: https://pkg.go.dev/[email protected]#Is Signed-off-by: Sebastiaan van Stijn <[email protected]>
2025-09-01fix deprecation comment for (FlagSet.)ParseErrorsWhitelistSebastiaan van Stijn
Commit 7412009ab0f29ad89cbc6625911a58c0618cf31e added back these types and marked them as deprecated, but did not use the correct format as documented in the [go documentation]. Deprecation comments should be in their own paragraph within the GoDoc, and start with `Deprecated:`, which is case-sensitive. Currently, the deprecation comment is not properly detected, and does not show up as deprecated on [pkg.go.dev]. This patch; - Fixes the deprecation comments to be in the right format. - Updates the GoDoc to use a "docs link" to refer to their replacement, which creates a link to those types on pkg.go.dev. - Adds back GoDoc for the deprecated functions to make sure the GoDoc is in the correct format and keep linters happy. [go documentation]: https://go.dev/doc/comment#deprecations [pkg.go.dev]: https://pkg.go.dev/github.com/spf13/[email protected]#ParseErrorsWhitelist Signed-off-by: Sebastiaan van Stijn <[email protected]>
2025-09-01fix: Restore ParseErrorsWhitelist name for nowTomas Aschan
This will be removed in a future release, but is reintroduced here to not break backwards compatibility.
2025-08-31Merge pull request #444 from spf13/reset-args-even-if-emptyv1.0.8Tomas Aschan
Reset args on re-parse even if empty
2025-08-30Use errors.Is instead of equality checkTomas Aschan
2025-08-29Reset args on re-parse even if emptyreset-args-even-if-emptyTomas Aschan
This ensures fs.Args() returns the expected thing after every parse. Fixes #439.
2025-08-29fix: Don't print ErrHelp in ParseAllTomas Aschan
This is a fixup of #407 to ensure behavior of ExitOnError is consistent.
2025-08-29Merge branch 'master' into fix-errhelpTomas Aschan
2025-07-17Merge pull request #261 from dubrie/masterTomas Aschan
Switching from whitelist to Allowlist terminology. Fixes #294
2025-07-17Merge pull request #364 from vaguecoder/duplicate-errorTomas Aschan
Remove Redundant "Unknown-Flag" Error
2025-07-17Ensure output is written also from ParseAllTomas Aschan
2025-07-17Ensure output is written to correct streamTomas Aschan
2025-06-09fix help message for Func and BoolFunc flags #430Georges Varouchas
* have '.Type()' for boolfuncValue return "boolfunc" (dedicated value, which now makes it distinct from funcValue) * hide extra "(default )" by stating that "" should be treated as a zero value for a boolFlag note: - a boolfuncValue matches 'case boolFlag:', as it implements the boolFlag interface, - treating "" as a value which shouldn't trigger a "(default )" for a regular Bool flag does not look like a breaking change * hide extra "[=something]" for boolfuncValue * set default placeholder name for "boolfunc" and "func" flag types
2025-06-01Merge pull request #409 from ShawnJeffersonWang/masterTomas Aschan
fix: correct argument length check in FlagSet.Parse
2025-05-14Merge pull request #424 from valdar/issue/423Tomas Aschan
fix #423 : Add helper function and some documentation to parse shorthand go test flags.
2025-05-14fix #423 : Add helper function and some documentation to parse shorthand go ↵Andrea Tarocchi
test flags.
2025-04-21feat: Use error structs for most returned errorsEthan P.
This allows callers to differentiate between error types without having to parse the error message string.
2025-03-18Fix defaultIsZeroValue check for generic Value typeMidnightRocket
2024-07-23fix: correct argument length check in FlagSet.Parseshawn
Signed-off-by: shawn <[email protected]>
2024-06-12flag: Emulate stdlib behavior and do not print ErrHelpTravis Cline
2022-11-19Remove Redundant "Unknown-Flag" ErrorBhargav Ravuri
Signed-off-by: Bhargav Ravuri <[email protected]>
2020-06-02Switching from whitelist to Allowlist terminologyBill Johnson
2020-05-04Add exported functions to preserve `pkg/flag` compatibility (#220)Ryan McKern
* Rename out() to Output() This brings behavior inline with go's flag library, and allows for printing output directly to whatever the current FlagSet is using for output. This change will make it easier to correctly emit output to stdout or stderr (e.g. a user has requested a help screen, which should emit to stdout since it's the desired outcome). * improve compat. with pkg/flag by adding Name() pkg/flag has a public `Name()` function, which returns the name of the flag set when called. This commit adds that function, as well as a test for it. * Streamline testing Name() Testing `Name()` will move into its own explicit test, instead of running inline during `TestAddFlagSet()`. Co-authored-by: Chloe Kudryavtsev <[email protected]> Co-authored-by: Chloe Kudryavtsev <[email protected]>
2019-09-17Merge pull request #216 from therealmitchconnors/elegantMitch Connors
Implement SliceValue for better list semantics
2019-09-10Add SliceValue Commentstherealmitchconnors
2019-08-16Add first SliceValue implementationstherealmitchconnors
2019-06-16Fix package docDavid Schneider
Signed-off-by: David Schneider <[email protected]>
2018-08-31Fix panic when parsing unknown flag followed by empty argument (#173)v1.0.3Oren Shomron
Signed-off-by: Oren Shomron <[email protected]>
2018-06-01Allow bubbling up of -test.* flags (#169)Joffrey F
Based on patch suggested here: https://github.com/spf13/cobra/issues/597#issuecomment-385984076
2018-04-12Typo correction in flag.go (#164)v1.0.1Saakallya Biswas
2018-04-10Allow Users To Show Deprecated Flags (#163)Eric Paris
They have to explicitly unhide a deprecated flag to keep the current behavior.
2018-04-03make x.Parsed() return true after AddGoFlagSet(x) and pflag.Parse() (#162)childe
* make GoFlagSets.Parsed() true after pflag.Parse some third part lib such as glog use go flag package, and its some actions depends on if goflag.Parsed(). * add test case for goflag.CommandLine.Parsed() * add comment to goflag.CommandLine.Parsed test case
2018-03-30add ability to ignore unknown flags (#160)Rajat Jindal
* add ability to ignore unknown flags * add testcases * add 2 more patterns to the testcase * handle --unknownflag=val arg and -u=val arg scenario * add ParseErrorsWhiteList to extend error handling during parsing
2018-03-28Add multiline wrapping support (#155)mkishere
* Add multiline wrapping support With reference to golang/go#20799, pflag now will respect newline in usage string and do wrap accordingly. Also add test cases for testing * Break at \n only if \n pos<wrap
2017-11-06Add uintSlice and boolSlice to name prettifier (#150)Steven Roose
2017-10-20Prevent printing when using ContinueOnError (#144)Steven Roose
2017-10-05Fixing Count flag usage string (#141)gonix
2017-10-02Fix SetNormalizeFunc (#137)Diego Becciolini
Related to https://github.com/spf13/cobra/issues/521
2017-09-30Generate flag error output for errors returned from the parseFunc (#138)Michael Porter
2017-09-01New: renamed intSlice to ints in usageChristophe Serafin
2017-09-01New: added a default name to avoid stringSlice in the usage message.Christophe Serafin
2017-05-05Testing for Shorthand LookupEric Paris
2017-05-05Add example to ShorthandLookupAlbert Nigmatzianov
2017-05-05Add note about panic in ShorthandLookupAlbert Nigmatzianov
2017-05-05Allow lookup by shorthand (#106)Charlie R.C
2017-04-27Unify error message for panic and f.outAlbert Nigmatzianov
2017-04-26Use comparison a string with "" instead of comparison of lenAlbert Nigmatzianov