Skip to content

Commit

Permalink
reproduce sub command bug
Browse files Browse the repository at this point in the history
  • Loading branch information
posener committed Oct 23, 2019
1 parent 2f2ff27 commit e24ae2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
31 changes: 22 additions & 9 deletions complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func TestCompleter_Complete(t *testing.T) {
"-flag1": PredictAnything,
"-flag2": PredictNothing,
},
Sub: Commands{
"sub11": {},
},
},
"sub2": {
Flags: Flags{
Expand All @@ -28,6 +31,11 @@ func TestCompleter_Complete(t *testing.T) {
},
Args: PredictFiles("*.md"),
},
"sub3": {
Sub: Commands{
"sub3": {},
},
},
},
Flags: Flags{
"-o": PredictFiles("*.txt"),
Expand All @@ -47,7 +55,7 @@ func TestCompleter_Complete(t *testing.T) {
{
line: "cmd ",
point: -1,
want: []string{"sub1", "sub2"},
want: []string{"sub1", "sub2", "sub3"},
},
{
line: "cmd -",
Expand All @@ -57,7 +65,7 @@ func TestCompleter_Complete(t *testing.T) {
{
line: "cmd -h ",
point: -1,
want: []string{"sub1", "sub2"},
want: []string{"sub1", "sub2", "sub3"},
},
{
line: "cmd -global1 ", // global1 is known follow flag
Expand All @@ -67,7 +75,7 @@ func TestCompleter_Complete(t *testing.T) {
{
line: "cmd sub",
point: -1,
want: []string{"sub1", "sub2"},
want: []string{"sub1", "sub2", "sub3"},
},
{
line: "cmd sub1",
Expand All @@ -82,7 +90,12 @@ func TestCompleter_Complete(t *testing.T) {
{
line: "cmd sub1 ",
point: -1,
want: []string{},
want: []string{"sub11"},
},
{
line: "cmd sub3 ",
point: -1,
want: []string{"sub3"},
},
{
line: "cmd sub1 -",
Expand Down Expand Up @@ -142,7 +155,7 @@ func TestCompleter_Complete(t *testing.T) {
{
line: "cmd -no-such-flag ",
point: -1,
want: []string{"sub1", "sub2"},
want: []string{"sub1", "sub2", "sub3"},
},
{
line: "cmd -no-such-flag -",
Expand All @@ -157,7 +170,7 @@ func TestCompleter_Complete(t *testing.T) {
{
line: "cmd no-such-command ",
point: -1,
want: []string{"sub1", "sub2"},
want: []string{"sub1", "sub2", "sub3"},
},
{
line: "cmd -o ",
Expand Down Expand Up @@ -212,12 +225,12 @@ func TestCompleter_Complete(t *testing.T) {
{
line: "cmd -o ./readme.md ",
point: -1,
want: []string{"sub1", "sub2"},
want: []string{"sub1", "sub2", "sub3"},
},
{
line: "cmd -o=./readme.md ",
point: -1,
want: []string{"sub1", "sub2"},
want: []string{"sub1", "sub2", "sub3"},
},
{
line: "cmd -o sub2 -flag3 ",
Expand Down Expand Up @@ -256,7 +269,7 @@ func TestCompleter_Complete(t *testing.T) {
line: "cmd -o ",
// ^
point: 4,
want: []string{"sub1", "sub2"},
want: []string{"sub1", "sub2", "sub3"},
},
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/posener/complete

require github.com/hashicorp/go-multierror v1.0.0

go 1.13

0 comments on commit e24ae2e

Please sign in to comment.