Skip to content

Conversation

@nmvalera
Copy link
Contributor

@nmvalera nmvalera commented Apr 12, 2025

Description

This PR adds support for pflag.BoolSlice, pflag.UintSlice and pflag.Float64Slice (see failing test below).

Note: there are other pflag slices not supported, but this PR propose to add supports for at least one of each kind: Bool, Uint, & Float64.

Extra Information

Below is a simple failing test

func TestBindPFlagsSlices(t *testing.T) {
	set := pflag.NewFlagSet("test", pflag.ContinueOnError)
        set.IntSlice("intslice", []int{}, "")
	set.BoolSlice("boolslice", []bool{}, "")
	set.Float64Slice("float64slice", []float64{}, "")
	set.UintSlice("uintslice", []uint{}, "")

	v := New()
	v.BindPFlags(set)

	// Does not fail as effectively supported
	set.Set("intslice", "1,2")
	assert.Equal(t, []int{1, 2}, v.Get("intslice"))

	// Fails as not supported
	set.Set("boolslice", "true,false")
	assert.Equal(t, []bool{true, false}, v.Get("boolslice"))

	// Fails as not supported
	set.Set("float64slice", "1.1,2.2")
	assert.Equal(t, []float64{1.1, 2.2}, v.Get("float64slice"))

	// Fails as not supported
	set.Set("uintslice", "1,2")
	assert.Equal(t, []uint{1, 2}, v.Get("uintslice"))
}

@nmvalera
Copy link
Contributor Author

nmvalera commented Apr 12, 2025

This PR is open as a draft as it requires some methods in the sf13/cast package that are currently not implemented. I have open this PR on cast to add it. Once merged and released on cast, I'll update this PR and open it.

@CLAassistant
Copy link

CLAassistant commented Apr 12, 2025

CLA assistant check
All committers have signed the CLA.

@sagikazarmark
Copy link
Collaborator

Cast PR merged, cast version updated on master

@nmvalera nmvalera marked this pull request as ready for review May 20, 2025 09:26
@nmvalera
Copy link
Contributor Author

@sagikazarmark This is ready for review. Thanks

@sagikazarmark sagikazarmark added the kind/enhancement New feature or request label Jun 3, 2025
@sagikazarmark sagikazarmark merged commit 260b8e9 into spf13:master Jun 3, 2025
82 of 85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants