Update module github.com/spf13/pflag to v1.0.9

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2025-09-01 16:22:21 +00:00
committed by GitHub
parent 6d210dd074
commit 11dedf8b4a
7 changed files with 80 additions and 14 deletions

View File

@@ -137,12 +137,16 @@ const (
PanicOnError
)
// ParseErrorsWhitelist defines the parsing errors that can be ignored
type ParseErrorsWhitelist struct {
// ParseErrorsAllowlist defines the parsing errors that can be ignored
type ParseErrorsAllowlist struct {
// UnknownFlags will ignore unknown flags errors and continue parsing rest of the flags
UnknownFlags bool
}
// DEPRECATED: please use ParseErrorsAllowlist instead
// This type will be removed in a future release
type ParseErrorsWhitelist = ParseErrorsAllowlist
// NormalizedName is a flag name that has been normalized according to rules
// for the FlagSet (e.g. making '-' and '_' equivalent).
type NormalizedName string
@@ -158,8 +162,12 @@ type FlagSet struct {
// help/usage messages.
SortFlags bool
// ParseErrorsWhitelist is used to configure a whitelist of errors
ParseErrorsWhitelist ParseErrorsWhitelist
// ParseErrorsAllowlist is used to configure an allowlist of errors
ParseErrorsAllowlist ParseErrorsAllowlist
// DEPRECATED: please use ParseErrorsAllowlist instead
// This field will be removed in a future release
ParseErrorsWhitelist ParseErrorsAllowlist
name string
parsed bool
@@ -928,7 +936,6 @@ func VarP(value Value, name, shorthand, usage string) {
// returns the error.
func (f *FlagSet) fail(err error) error {
if f.errorHandling != ContinueOnError {
fmt.Fprintln(f.Output(), err)
f.usage()
}
return err
@@ -986,6 +993,8 @@ func (f *FlagSet) parseLongArg(s string, args []string, fn parseFunc) (a []strin
f.usage()
return a, ErrHelp
case f.ParseErrorsWhitelist.UnknownFlags:
fallthrough
case f.ParseErrorsAllowlist.UnknownFlags:
// --unknown=unknownval arg ...
// we do not want to lose arg in this case
if len(split) >= 2 {
@@ -1044,6 +1053,8 @@ func (f *FlagSet) parseSingleShortArg(shorthands string, args []string, fn parse
err = ErrHelp
return
case f.ParseErrorsWhitelist.UnknownFlags:
fallthrough
case f.ParseErrorsAllowlist.UnknownFlags:
// '-f=arg arg ...'
// we do not want to lose arg in this case
if len(shorthands) > 2 && shorthands[1] == '=' {
@@ -1158,12 +1169,12 @@ func (f *FlagSet) Parse(arguments []string) error {
}
f.parsed = true
f.args = make([]string, 0, len(arguments))
if len(arguments) == 0 {
return nil
}
f.args = make([]string, 0, len(arguments))
set := func(flag *Flag, value string) error {
return f.Set(flag.Name, value)
}
@@ -1174,7 +1185,10 @@ func (f *FlagSet) Parse(arguments []string) error {
case ContinueOnError:
return err
case ExitOnError:
fmt.Println(err)
if errors.Is(err, ErrHelp) {
os.Exit(0)
}
fmt.Fprintln(f.Output(), err)
os.Exit(2)
case PanicOnError:
panic(err)
@@ -1200,6 +1214,10 @@ func (f *FlagSet) ParseAll(arguments []string, fn func(flag *Flag, value string)
case ContinueOnError:
return err
case ExitOnError:
if errors.Is(err, ErrHelp) {
os.Exit(0)
}
fmt.Fprintln(f.Output(), err)
os.Exit(2)
case PanicOnError:
panic(err)

View File

@@ -8,6 +8,7 @@ import (
goflag "flag"
"reflect"
"strings"
"time"
)
// go test flags prefixes
@@ -113,6 +114,38 @@ func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) {
f.addedGoFlagSets = append(f.addedGoFlagSets, newSet)
}
// CopyToGoFlagSet will add all current flags to the given Go flag set.
// Deprecation remarks get copied into the usage description.
// Whenever possible, a flag gets added for which Go flags shows
// a proper type in the help message.
func (f *FlagSet) CopyToGoFlagSet(newSet *goflag.FlagSet) {
f.VisitAll(func(flag *Flag) {
usage := flag.Usage
if flag.Deprecated != "" {
usage += " (DEPRECATED: " + flag.Deprecated + ")"
}
switch value := flag.Value.(type) {
case *stringValue:
newSet.StringVar((*string)(value), flag.Name, flag.DefValue, usage)
case *intValue:
newSet.IntVar((*int)(value), flag.Name, *(*int)(value), usage)
case *int64Value:
newSet.Int64Var((*int64)(value), flag.Name, *(*int64)(value), usage)
case *uintValue:
newSet.UintVar((*uint)(value), flag.Name, *(*uint)(value), usage)
case *uint64Value:
newSet.Uint64Var((*uint64)(value), flag.Name, *(*uint64)(value), usage)
case *durationValue:
newSet.DurationVar((*time.Duration)(value), flag.Name, *(*time.Duration)(value), usage)
case *float64Value:
newSet.Float64Var((*float64)(value), flag.Name, *(*float64)(value), usage)
default:
newSet.Var(flag.Value, flag.Name, usage)
}
})
}
// ParseSkippedFlags explicitly Parses go test flags (i.e. the one starting with '-test.') with goflag.Parse(),
// since by default those are skipped by pflag.Parse().
// Typical usage example: `ParseGoTestFlags(os.Args[1:], goflag.CommandLine)`
@@ -125,3 +158,4 @@ func ParseSkippedFlags(osArgs []string, goFlagSet *goflag.FlagSet) error {
}
return goFlagSet.Parse(skippedFlags)
}

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/csv"
"fmt"
"sort"
"strings"
)
@@ -62,8 +63,15 @@ func (s *stringToStringValue) Type() string {
}
func (s *stringToStringValue) String() string {
keys := make([]string, 0, len(*s.value))
for k := range *s.value {
keys = append(keys, k)
}
sort.Strings(keys)
records := make([]string, 0, len(*s.value)>>1)
for k, v := range *s.value {
for _, k := range keys {
v := (*s.value)[k]
records = append(records, k+"="+v)
}

View File

@@ -48,7 +48,13 @@ func (d *timeValue) Type() string {
return "time"
}
func (d *timeValue) String() string { return d.Time.Format(time.RFC3339Nano) }
func (d *timeValue) String() string {
if d.Time.IsZero() {
return ""
} else {
return d.Time.Format(time.RFC3339Nano)
}
}
// GetTime return the time value of a flag with the given name
func (f *FlagSet) GetTime(name string) (time.Time, error) {