@@ -704,12 +704,17 @@ func TestCommand_SliceFlags(t *testing.T) {
704704
705705 t .Run ("Inherited" , func (t * testing.T ) {
706706 const env = "SERPENT_TEST_ARRAY"
707+ type childArr string
708+ const (
709+ childShadowsArr childArr = "shadows"
710+ childRedeclaresArr childArr = "redeclares"
711+ )
707712 for _ , tc := range []struct {
708- name string
709- args []string
710- env string
711- shadow bool
712- want []string
713+ name string
714+ args []string
715+ env string
716+ child childArr
717+ want []string
713718 }{
714719 {name : "BeforeChild" , args : []string {"--arr" , "one" , "child" , "leaf" }, want : []string {"one" }},
715720 {name : "AfterLeaf" , args : []string {"child" , "leaf" , "--arr=one" }, want : []string {"one" }},
@@ -719,7 +724,8 @@ func TestCommand_SliceFlags(t *testing.T) {
719724 {name : "AfterUnknownFlag" , args : []string {"child" , "leaf" , "--leaf-only" , "--arr" , "one" }, want : []string {"one" }},
720725 {name : "PartiallyParsed" , args : []string {"--arr" , "one" , "child" , "leaf" , "--leaf-only" , "--arr" , "two" }, want : []string {"one" , "two" }},
721726 {name : "Clear" , args : []string {"--arr" , "one" , "child" , "leaf" , "--arr=" , "--arr" , "two" }, env : "env" , want : []string {"two" }},
722- {name : "Shadowed" , args : []string {"--arr" , "one" , "child" , "leaf" , "--arr" , "two" }, shadow : true , want : []string {"one" , "two" }},
727+ {name : "Shadowed" , args : []string {"--arr" , "one" , "child" , "leaf" , "--arr" , "two" }, child : childShadowsArr , want : []string {"one" , "two" }},
728+ {name : "SameValueRedeclared" , args : []string {"--arr" , "one" , "child" , "leaf" , "--arr" , "two" }, child : childRedeclaresArr , want : []string {"one" , "two" }},
723729 } {
724730 t .Run (tc .name , func (t * testing.T ) {
725731 var inherited , shadowed []string
@@ -733,18 +739,19 @@ func TestCommand_SliceFlags(t *testing.T) {
733739 Handler : func (* serpent.Invocation ) error {
734740 called = true
735741 require .Equal (t , tc .want , * got )
736- if tc .shadow {
742+ if tc .child == childShadowsArr {
737743 require .Equal (t , tc .want , inherited )
738744 }
739745 return nil
740746 },
741747 }
742748 child := & serpent.Command {Use : "child" , Children : []* serpent.Command {leaf }}
743- if tc .shadow {
744- child .Options = serpent.OptionSet {
745- {Flag : "arr" , Value : serpent .StringArrayOf (& shadowed )},
746- }
749+ switch tc .child {
750+ case childShadowsArr :
751+ child .Options = serpent.OptionSet {{Flag : "arr" , Value : serpent .StringArrayOf (& shadowed )}}
747752 got = & shadowed
753+ case childRedeclaresArr :
754+ child .Options = serpent.OptionSet {{Flag : "arr" , Value : serpent .StringArrayOf (& inherited )}}
748755 }
749756 root := & serpent.Command {
750757 Use : "root" ,
0 commit comments