diff options
| author | Alex Dadgar <[email protected]> | 2017-08-23 13:16:52 -0700 |
|---|---|---|
| committer | Alex Dadgar <[email protected]> | 2017-08-24 17:35:36 -0700 |
| commit | 59e6151c5bb3277462aa4c484af0e6f853df662d (patch) | |
| tree | b5a39d189057c9c10df23391ee64ede439fbebc2 /complete_test.go | |
| parent | 5075f6d6e69fb7b5a20a79ca0b87b16a484e2d2a (diff) | |
Allow restricting completion of flags
This PR allows a command to specify that flags should only be completed
when a prefix is present. The motivation behind this is to have the
initial complation to prefer displaying argument completions and only
display flag completions when the user enters "hyphen <tab>".
Diffstat (limited to 'complete_test.go')
| -rw-r--r-- | complete_test.go | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/complete_test.go b/complete_test.go index 1a42da1..768f2c8 100644 --- a/complete_test.go +++ b/complete_test.go @@ -25,6 +25,13 @@ func TestCompleter_Complete(t *testing.T) { }, Args: PredictFiles("*.md"), }, + "sub3": { + Flags: Flags{ + "-flag4": PredictAnything, + "-flag5": PredictNothing, + }, + FlagsRequirePrefix: "-", + }, }, Flags: Flags{ "-o": PredictFiles("*.txt"), @@ -41,7 +48,7 @@ func TestCompleter_Complete(t *testing.T) { }{ { args: "", - want: []string{"sub1", "sub2", "-h", "-global1", "-o"}, + want: []string{"sub1", "sub2", "sub3", "-h", "-global1", "-o"}, }, { args: "-", @@ -49,7 +56,7 @@ func TestCompleter_Complete(t *testing.T) { }, { args: "-h ", - want: []string{"sub1", "sub2", "-h", "-global1", "-o"}, + want: []string{"sub1", "sub2", "sub3", "-h", "-global1", "-o"}, }, { args: "-global1 ", // global1 is known follow flag @@ -57,7 +64,7 @@ func TestCompleter_Complete(t *testing.T) { }, { args: "sub", - want: []string{"sub1", "sub2"}, + want: []string{"sub1", "sub2", "sub3"}, }, { args: "sub1", @@ -68,6 +75,10 @@ func TestCompleter_Complete(t *testing.T) { want: []string{"sub2"}, }, { + args: "sub3", + want: []string{"sub3"}, + }, + { args: "sub1 ", want: []string{"-flag1", "-flag2", "-h", "-global1"}, }, @@ -108,12 +119,20 @@ func TestCompleter_Complete(t *testing.T) { want: []string{"-flag1", "-flag2", "-h", "-global1"}, }, { + args: "sub3 ", + want: []string{"-h", "-global1"}, + }, + { + args: "sub3 -", + want: []string{"-flag4", "-flag5", "-h", "-global1"}, + }, + { args: "-no-such-flag", want: []string{}, }, { args: "-no-such-flag ", - want: []string{"sub1", "sub2", "-h", "-global1", "-o"}, + want: []string{"sub1", "sub2", "sub3", "-h", "-global1", "-o"}, }, { args: "no-such-command", @@ -121,7 +140,7 @@ func TestCompleter_Complete(t *testing.T) { }, { args: "no-such-command ", - want: []string{"sub1", "sub2", "-h", "-global1", "-o"}, + want: []string{"sub1", "sub2", "sub3", "-h", "-global1", "-o"}, }, { args: "-o ", @@ -149,7 +168,7 @@ func TestCompleter_Complete(t *testing.T) { }, { args: "-o ./readme.md ", - want: []string{"sub1", "sub2", "-h", "-global1", "-o"}, + want: []string{"sub1", "sub2", "sub3", "-h", "-global1", "-o"}, }, { args: "-o sub2 -flag3 ", |
