vendor: github.com/urfave/cli v1.22.9
The regression in v1.22.2 has been resolved, so we can drop the replace rule and use the latest v1.22.x version. full diff: https://github.com/urfave/cli/compare/v1.22.1...v1.22.9 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
54
vendor/github.com/urfave/cli/flag_string_slice.go
generated
vendored
54
vendor/github.com/urfave/cli/flag_string_slice.go
generated
vendored
@@ -17,7 +17,7 @@ func (f *StringSlice) Set(value string) error {
|
||||
|
||||
// String returns a readable representation of this value (for usage defaults)
|
||||
func (f *StringSlice) String() string {
|
||||
return fmt.Sprintf("%s", *f)
|
||||
return strings.Join(*f, ",")
|
||||
}
|
||||
|
||||
// Value returns the slice of strings set by this flag
|
||||
@@ -128,11 +128,57 @@ func (c *Context) GlobalStringSlice(name string) []string {
|
||||
func lookupStringSlice(name string, set *flag.FlagSet) []string {
|
||||
f := set.Lookup(name)
|
||||
if f != nil {
|
||||
parsed, err := (f.Value.(*StringSlice)).Value(), error(nil)
|
||||
if err != nil {
|
||||
value, ok := f.Value.(*StringSlice)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return parsed
|
||||
// extract the slice from asserted value
|
||||
slice := value.Value()
|
||||
|
||||
// extract default value from the flag
|
||||
var defaultVal []string
|
||||
for _, v := range strings.Split(f.DefValue, ",") {
|
||||
defaultVal = append(defaultVal, v)
|
||||
}
|
||||
|
||||
// if the current value is not equal to the default value
|
||||
// remove the default values from the flag
|
||||
if !isStringSliceEqual(slice, defaultVal) {
|
||||
for _, v := range defaultVal {
|
||||
slice = removeFromStringSlice(slice, v)
|
||||
}
|
||||
}
|
||||
return slice
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeFromStringSlice(slice []string, val string) []string {
|
||||
for i, v := range slice {
|
||||
if v == val {
|
||||
ret := append([]string{}, slice[:i]...)
|
||||
ret = append(ret, slice[i+1:]...)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
return slice
|
||||
}
|
||||
|
||||
func isStringSliceEqual(newValue, defaultValue []string) bool {
|
||||
// If one is nil, the other must also be nil.
|
||||
if (newValue == nil) != (defaultValue == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(newValue) != len(defaultValue) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i, v := range newValue {
|
||||
if v != defaultValue[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user