Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*Slice: don't mutate the underlying default value #1170

Merged
merged 1 commit into from Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion flag_int64_slice.go
Expand Up @@ -171,7 +171,9 @@ func lookupInt64Slice(name string, set *flag.FlagSet) []int64 {
func removeFromInt64Slice(slice []int64, val int64) []int64 {
for i, v := range slice {
if v == val {
return append(slice[:i], slice[i+1:]...)
ret := append([]int64{}, slice[:i]...)
ret = append(ret, slice[i+1:]...)
return ret
}
}
return slice
Expand Down
4 changes: 3 additions & 1 deletion flag_int_slice.go
Expand Up @@ -170,7 +170,9 @@ func lookupIntSlice(name string, set *flag.FlagSet) []int {
func removeFromIntSlice(slice []int, val int) []int {
for i, v := range slice {
if v == val {
return append(slice[:i], slice[i+1:]...)
ret := append([]int{}, slice[:i]...)
ret = append(ret, slice[i+1:]...)
return ret
}
}
return slice
Expand Down
4 changes: 3 additions & 1 deletion flag_string_slice.go
Expand Up @@ -156,7 +156,9 @@ func lookupStringSlice(name string, set *flag.FlagSet) []string {
func removeFromStringSlice(slice []string, val string) []string {
for i, v := range slice {
if v == val {
return append(slice[:i], slice[i+1:]...)
ret := append([]string{}, slice[:i]...)
ret = append(ret, slice[i+1:]...)
return ret
}
}
return slice
Expand Down