@@ -33,19 +33,19 @@ func TestFindCmd(t *testing.T) {
3333 cmd := newCmd ("root" , "" )
3434 cmd .AddCmd (newCmd ("child1" , "" ))
3535 cmd .AddCmd (newCmd ("child2" , "" ))
36- res , err := cmd .FindCmd ([]string {"child1" })
36+ res , err := cmd .FindCmd ([]string {"child1" }, false )
3737 if err != nil {
3838 t .Fatal ("finding should work" )
3939 }
4040 assert .Equal (t , res .Name , "child1" )
4141
42- res , err = cmd .FindCmd ([]string {"child2" })
42+ res , err = cmd .FindCmd ([]string {"child2" }, false )
4343 if err != nil {
4444 t .Fatal ("finding should work" )
4545 }
4646 assert .Equal (t , res .Name , "child2" )
4747
48- res , err = cmd .FindCmd ([]string {"child3" })
48+ res , err = cmd .FindCmd ([]string {"child3" }, false )
4949 if err == nil {
5050 t .Fatal ("should not find this child!" )
5151 }
@@ -58,19 +58,49 @@ func TestFindAlias(t *testing.T) {
5858 subcmd .Aliases = []string {"alias1" , "alias2" }
5959 cmd .AddCmd (subcmd )
6060
61- res , err := cmd .FindCmd ([]string {"alias1" })
61+ res , err := cmd .FindCmd ([]string {"alias1" }, false )
6262 if err != nil {
6363 t .Fatal ("finding alias should work" )
6464 }
6565 assert .Equal (t , res .Name , "child1" )
6666
67- res , err = cmd .FindCmd ([]string {"alias2" })
67+ res , err = cmd .FindCmd ([]string {"alias2" }, false )
6868 if err != nil {
6969 t .Fatal ("finding alias should work" )
7070 }
7171 assert .Equal (t , res .Name , "child1" )
7272
73- res , err = cmd .FindCmd ([]string {"alias3" })
73+ res , err = cmd .FindCmd ([]string {"alias3" }, false )
74+ if err == nil {
75+ t .Fatal ("should not find this child!" )
76+ }
77+ assert .Nil (t , res )
78+ }
79+
80+ func TestFindCmdPrefix (t * testing.T ) {
81+ cmd := newCmd ("root" , "" )
82+ cmd .AddCmd (newCmd ("cmdone" , "" ))
83+ cmd .AddCmd (newCmd ("cmdtwo" , "" ))
84+
85+ res , err := cmd .FindCmd ([]string {"cmdo" }, true )
86+ if err != nil {
87+ t .Fatal ("finding should work" )
88+ }
89+ assert .Equal (t , res .Name , "cmdone" )
90+
91+ res , err = cmd .FindCmd ([]string {"cmdt" }, true )
92+ if err != nil {
93+ t .Fatal ("finding should work" )
94+ }
95+ assert .Equal (t , res .Name , "cmdtwo" )
96+
97+ res , err = cmd .FindCmd ([]string {"c" }, true )
98+ if err == nil {
99+ t .Fatal ("should not find this child!" )
100+ }
101+ assert .Nil (t , res )
102+
103+ res , err = cmd .FindCmd ([]string {"cmd" }, true )
74104 if err == nil {
75105 t .Fatal ("should not find this child!" )
76106 }
0 commit comments