File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change 11package flags
22
33import (
4- "fmt"
54 "strings"
65
76 "github.com/spf13/pflag"
@@ -25,7 +24,12 @@ func (f *cidrSliceFlag) String() string {
2524
2625func (f * cidrSliceFlag ) Set (value string ) error {
2726 if value == "" {
28- return fmt .Errorf ("value cannot be empty" )
27+ // If it's the first value to be set to the flag, we set it to an empty list
28+ // Otherwise, we just ignore an empty value
29+ if len (f .value ) == 0 {
30+ f .value = []string {}
31+ }
32+ return nil
2933 }
3034
3135 cidrs := strings .Split (value , "," )
Original file line number Diff line number Diff line change @@ -586,9 +586,17 @@ func TestCIDRSliceFlag(t *testing.T) {
586586 isValid : false ,
587587 },
588588 {
589- description : "invalid empty value" ,
590- value1 : utils .Ptr ("" ),
591- isValid : false ,
589+ description : "empty value to specify empty list" ,
590+ value1 : utils .Ptr ("" ),
591+ isValid : true ,
592+ expectedValue : []string {},
593+ },
594+ {
595+ description : "valid value and empty value" ,
596+ value1 : utils .Ptr ("198.51.100.14/24" ),
597+ value2 : utils .Ptr ("" ),
598+ isValid : true ,
599+ expectedValue : []string {"198.51.100.14/24" },
592600 },
593601 {
594602 description : "invalid empty value in list" ,
You can’t perform that action at this time.
0 commit comments