diff --git a/complete_test.go b/complete_test.go index a6daa98..6bee548 100644 --- a/complete_test.go +++ b/complete_test.go @@ -25,7 +25,7 @@ func TestCompleter_Complete(t *testing.T) { "sub2": { Flags: map[string]Predicate{ "-flag2": PredictNothing, - "-flag3": PredictNothing, + "-flag3": PredictSet("opt1", "opt2", "opt12"), }, Args: PredictDirs("./tests/").Or(PredictFiles("./tests/*.md")), }, @@ -160,6 +160,18 @@ func TestCompleter_Complete(t *testing.T) { args: "-o ./complete.go ", 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 { diff --git a/gocomplete/complete.go b/gocomplete/complete.go index 57fbaa1..11a948f 100644 --- a/gocomplete/complete.go +++ b/gocomplete/complete.go @@ -58,7 +58,7 @@ func main() { "-benchtime": complete.PredictAnything, "-count": complete.PredictAnything, "-cover": complete.PredictNothing, - "-covermode": complete.PredictSet([]string{"set", "count", "atomic"}), + "-covermode": complete.PredictSet("set", "count", "atomic"), "-coverpkg": complete.PredictDirs("./"), "-cpu": complete.PredictAnything, "-run": predictTest("test"), diff --git a/predicate.go b/predicate.go index 08a6722..bcf48b8 100644 --- a/predicate.go +++ b/predicate.go @@ -37,7 +37,7 @@ var ( PredictAnything = Predicate{} ) -func PredictSet(options []string) Predicate { +func PredictSet(options ...string) Predicate { return Predicate{ Predictor: func() []Option { ret := make([]Option, len(options))