Skip to content

Comments

merge upstream v1.0.10#27

Merged
rsteube merged 70 commits intomasterfrom
merge-upstream-v1.0.10
Nov 7, 2025
Merged

merge upstream v1.0.10#27
rsteube merged 70 commits intomasterfrom
merge-upstream-v1.0.10

Conversation

@rsteube
Copy link
Member

@rsteube rsteube commented Nov 4, 2025

  • Switching from whitelist to Allowlist terminology
  • Update flag_test.go
  • Remove Redundant "Unknown-Flag" Error
  • flag: Emulate stdlib behavior and do not print ErrHelp
  • fix: correct argument length check in FlagSet.Parse
  • fix: add test for argument length check
  • add support equivalent to golang flag.TextVar(), also fixes the test failure as described in "./flag_test.go:1242:3: fmt.Println arg list ends with redundant newline" with go >= 1.18 spf13/pflag#368
  • add github actions
  • fix govet
  • disable unsupported dependency graph for now
  • Fix defaultIsZeroValue check for generic Value type
  • Add better test for defaultIsZeroValue for generic Value type
  • Improve readability for error in TestPrintDefaults
  • test: Commonly-returned error messages
  • feat: Use error structs for most returned errors
  • feat: Add getters to error structs
  • test: Add tests for error structs
  • Fix typos
  • - update text_test.go based on PR review comments - return is missing in one error path of GetText(), fixed
  • fix Add helper function and some documentation to parse shorthand go test flags spf13/pflag#423 : Add helper function and some documentation to parse shorthand go test flags.
  • add support for Func() and BoolFunc() Add flag.Func / flag.BoolFunc spf13/pflag#426
  • minor: fix typos in comments
  • fix help message for Func and BoolFunc flags Improve help text for a flag added by BoolFunc spf13/pflag#430
  • fix discrepancy in order of arguments for Func() and BoolFunc() fix order of arguments in new functions .Func() and .BoolFunc() spf13/pflag#433
  • Add support for time.Time flags
  • Use time.Time for expectations in time flag tests
  • Remove unnecessary time test stderr dev null redirect
  • Don't export TimeValue (yet)
  • Reduce duplication by forwarding to sibling functions
  • Ensure output is written to correct stream
  • Ensure output is written also from ParseAll
  • Omit zero time.Time default from usage line
  • add CopyToGoFlagSet
  • fix: Don't print ErrHelp in ParseAll
  • Print Default Values of String-to-String in Sorted Order
  • Reset args on re-parse even if empty
  • Use errors.Is instead of equality check
  • fix: Restore ParseErrorsWhitelist name for now
  • fix deprecation comment for (FlagSet.)ParseErrorsWhitelist
  • remove uses of errors.Is, which requires go1.13
  • move Func, BoolFunc, tests as they require go1.21
  • Test on Go 1.12

dubrie and others added 30 commits June 2, 2020 13:02
Signed-off-by: Bhargav Ravuri <vaguecoder0to.n@gmail.com>
Signed-off-by: shawn <xw2002121@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
…alue-for-generic-value-type

Fix defaultIsZeroValue check for generic Value types
Add tests to ensure invalid arguments and unknown flag error messages
don't change.
This allows callers to differentiate between error types without having
to parse the error message string.
feat: Use structs for errors returned by pflag.
- return is missing in one error path of GetText(), fixed
fix spf13#423 : Add helper function and some documentation to parse shorthand go test flags.
add support equivalent to golang flag.TextVar(), also fixes the test failure as described in spf13#368
Add support for two features which landed in the 'flag' package
from the standard library: Func() and BoolFunc()
and their two pflag specific versions: FuncP() and BoolFuncP()

fixes spf13#426
tomasaschan and others added 17 commits August 29, 2025 22:01
flag: Emulate stdlib behavior and do not print ErrHelp
This is a fixup of spf13#407 to ensure behavior of ExitOnError is consistent.
Signed-off-by: Bhargav Ravuri <vaguecoder0to.n@gmail.com>
Print Default Values of String-to-String in Sorted Order
This ensures fs.Args() returns the expected thing after every parse.

Fixes spf13#439.
fix: Don't print ErrHelp in ParseAll
This will be removed in a future release, but is reintroduced here to not break backwards compatibility.
fix: Restore ParseErrorsWhitelist name for now
Commit 7412009 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/pflag@v1.0.9#ParseErrorsWhitelist

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Commit 1bf832c 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/errors@go1.13#Is

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Commit 69bc3bd added support for Func()
and BoolFunc() to match stdlib. However, the Func method was added in
[go1.16.0], and BoolFunc in [go1.21.0], so running the tests on older
versions of Go would fail;

    docker run -it --rm -v ./:/pflag -w /pflag golang:1.21 sh -c 'go test -v ./...'
    # github.com/spf13/pflag [github.com/spf13/pflag.test]
    ./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)
    ./bool_func_test.go:113:21: undefined: io.Discard
    ./bool_func_test.go:116:28: cannot use stdFSet (type *flag.FlagSet) as type BoolFuncFlagSet in argument to runCase:
        *flag.FlagSet does not implement BoolFuncFlagSet (missing BoolFunc method)
    ./bool_func_test.go:139:7: undefined: errors.Is
    ./func_test.go:92:28: cannot use stdFSet (type *flag.FlagSet) as type FuncFlagSet in argument to runCase:
        *flag.FlagSet does not implement FuncFlagSet (missing Func method)
    ./func_test.go:119:21: undefined: io.Discard
    ./func_test.go:122:28: cannot use stdFSet (type *flag.FlagSet) as type FuncFlagSet in argument to runCase:
        *flag.FlagSet does not implement FuncFlagSet (missing Func method)
    ./func_test.go:145:7: undefined: errors.Is
    ./func_test.go:145:7: too many errors
    FAIL	github.com/spf13/pflag [build failed]

This patch moves the tests to a separate file that is not built for older
versions of Go.

[go1.16.0]: https://pkg.go.dev/flag@go1.16.0#Func
[go1.21.0]: https://pkg.go.dev/flag@go1.21.0#BoolFunc

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Since 1.12 is what we specify in go.mod, and therefore implicitly is what
we promise to work with, we should ensure that we don't introduce changes
which break this promise (e.g. as 1bf832c).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
fix deprecation comment for (FlagSet.)ParseErrorsWhitelist
remove uses of errors.Is, which requires go1.13, move go1.16/go1.21 tests to separate file
@rsteube rsteube force-pushed the merge-upstream-v1.0.10 branch 2 times, most recently from 8aed940 to e312ba0 Compare November 4, 2025 12:45
@coveralls
Copy link

coveralls commented Nov 4, 2025

Pull Request Test Coverage Report for Build 19162697504

Details

  • 226 of 388 (58.25%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.6%) to 54.124%

Changes Missing Coverage Covered Lines Changed/Added Lines %
errors.go 50 67 74.63%
flag.go 39 58 67.24%
func.go 10 30 33.33%
bool_func.go 11 34 32.35%
text.go 27 60 45.0%
time.go 44 94 46.81%
Totals Coverage Status
Change from base Build 10027008420: 0.6%
Covered Lines: 2638
Relevant Lines: 4874

💛 - Coveralls

@rsteube rsteube force-pushed the merge-upstream-v1.0.10 branch from 1eaf97e to 2a8de14 Compare November 7, 2025 08:16
@rsteube rsteube force-pushed the merge-upstream-v1.0.10 branch from 2a8de14 to 44262a6 Compare November 7, 2025 08:19
@rsteube rsteube marked this pull request as ready for review November 7, 2025 08:20
@rsteube rsteube force-pushed the merge-upstream-v1.0.10 branch from 44262a6 to d307325 Compare November 7, 2025 08:24
@rsteube rsteube force-pushed the merge-upstream-v1.0.10 branch from d307325 to fab9c2c Compare November 7, 2025 08:31
@rsteube rsteube merged commit 5bebd49 into master Nov 7, 2025
2 checks passed
@rsteube rsteube deleted the merge-upstream-v1.0.10 branch November 7, 2025 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add helper function and some documentation to parse shorthand go test flags