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": {
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 {

View File

@ -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"),

View File

@ -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))