nicer signature for PredictSet

This commit is contained in:
Eyal Posener 2017-05-06 00:53:03 +03:00
parent 87dada1ec4
commit 5dbf53eec0
3 changed files with 15 additions and 3 deletions

View File

@ -25,7 +25,7 @@ func TestCompleter_Complete(t *testing.T) {
"sub2": { "sub2": {
Flags: map[string]Predicate{ Flags: map[string]Predicate{
"-flag2": PredictNothing, "-flag2": PredictNothing,
"-flag3": PredictNothing, "-flag3": PredictSet("opt1", "opt2", "opt12"),
}, },
Args: PredictDirs("./tests/").Or(PredictFiles("./tests/*.md")), Args: PredictDirs("./tests/").Or(PredictFiles("./tests/*.md")),
}, },
@ -160,6 +160,18 @@ func TestCompleter_Complete(t *testing.T) {
args: "-o ./complete.go ", args: "-o ./complete.go ",
want: allGlobals, want: allGlobals,
}, },
{
args: "-o sub2 -flag3 ",
want: []string{"opt1", "opt2", "opt12"},
},
{
args: "-o sub2 -flag3 opt1",
want: []string{"opt1", "opt12"},
},
{
args: "-o sub2 -flag3 opt",
want: []string{"opt1", "opt2", "opt12"},
},
} }
for _, tt := range tests { for _, tt := range tests {

View File

@ -58,7 +58,7 @@ func main() {
"-benchtime": complete.PredictAnything, "-benchtime": complete.PredictAnything,
"-count": complete.PredictAnything, "-count": complete.PredictAnything,
"-cover": complete.PredictNothing, "-cover": complete.PredictNothing,
"-covermode": complete.PredictSet([]string{"set", "count", "atomic"}), "-covermode": complete.PredictSet("set", "count", "atomic"),
"-coverpkg": complete.PredictDirs("./"), "-coverpkg": complete.PredictDirs("./"),
"-cpu": complete.PredictAnything, "-cpu": complete.PredictAnything,
"-run": predictTest("test"), "-run": predictTest("test"),

View File

@ -37,7 +37,7 @@ var (
PredictAnything = Predicate{} PredictAnything = Predicate{}
) )
func PredictSet(options []string) Predicate { func PredictSet(options ...string) Predicate {
return Predicate{ return Predicate{
Predictor: func() []Option { Predictor: func() []Option {
ret := make([]Option, len(options)) ret := make([]Option, len(options))