Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Sep 26, 2023
1 parent f76eac0 commit 698cd22
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions example/cmd/compat.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"fmt"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -65,6 +67,11 @@ func init() {
return []string{"p1", "positional1"}, cobra.ShellCompDirectiveDefault
case 1:
return nil, cobra.ShellCompDirectiveDefault
case 2:
return []string{
fmt.Sprintf("args: %#v toComplete: %#v", args, toComplete),
"alternative",
}, cobra.ShellCompDirectiveNoFileComp
default:
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down
35 changes: 35 additions & 0 deletions example/cmd/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,40 @@ func TestCompat(t *testing.T) {
s.Run("compat", "--unset", "").
Expect(carapace.ActionValues().
Usage("no completions defined"))

s.Run("compat", "").
Expect(carapace.ActionValues(
"p1",
"positional1",
).Usage(""))

s.Run("compat", "positional1", "").
Expect(carapace.ActionValues(
"subdir/",
"go.mod",
"go.sum",
"README.md",
).NoSpace('/').
StyleF(style.ForPath).
Tag("files").
Usage(""))

s.Run("compat", "positional1", "main.go", "").
Expect(carapace.ActionValues(
`args: []string{"positional1", "main.go"} toComplete: ""`,
"alternative",
).Usage(""))

s.Run("compat", "positional1", "main.go", "a").
Expect(carapace.ActionValues(
`args: []string{"positional1", "main.go"} toComplete: "a"`,
"alternative",
).Usage(""))

s.Run("compat", "--nospace", "one", "positional1", "--", "main.go", "a").
Expect(carapace.ActionValues(
`args: []string{"positional1", "main.go"} toComplete: "a"`,
"alternative",
).Usage(""))
})
}

0 comments on commit 698cd22

Please sign in to comment.