Skip to content

Implement SliceValue for ipNetSlice - #548

Merged
tomasaschan merged 1 commit into
spf13:masterfrom
rohitmahadevan:ipnetslice-slicevalue
Nov 17, 2026
Merged

tomasaschan merged 1 commit into
spf13:masterfrom
rohitmahadevan:ipnetslice-slicevalue

Conversation

@rohitmahadevan

Copy link
Copy Markdown

ipNetSliceValue is the only list flag type that doesn't implement SliceValue. The interface comment says it covers all flags that hold a list, and every other *_slice.go (plus stringArray) has Append, Replace and GetSlice.

Since callers find SliceValue with a type assertion, nothing fails at compile time. Code that resets list flags just skips IPNetSlice flags:

fs.VisitAll(func(f *pflag.Flag) {
	if sv, ok := f.Value.(pflag.SliceValue); ok {
		_ = sv.Replace([]string{"10.0.0.0/8"})
	}
})

After --cidrs=192.168.1.1/24 --cidrs=fd00::/64, the flag still holds both networks.

The new methods follow ip_slice.go, using net.ParseCIDR and the same error message Set already returns. Replace builds the new slice before assigning it, so a bad entry leaves the current value unchanged.

The tests are copies of the IPSlice ones: the type assertion, rejecting invalid CIDRs in Append and Replace, and an Append/Replace/GetSlice round trip.

@CLAassistant

CLAassistant commented Nov 17, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@tomasaschan
tomasaschan merged commit 53c3173 into spf13:master Nov 17, 2026
8 checks passed
@rohitmahadevan
rohitmahadevan deleted the ipnetslice-slicevalue branch November 18, 2026 13:47
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.

3 participants