From 698cd22cdab23a0b18c71d19baa003ae7f91dcf8 Mon Sep 17 00:00:00 2001 From: rsteube Date: Tue, 26 Sep 2023 15:27:14 +0200 Subject: [PATCH] tmp --- example/cmd/compat.go | 7 +++++++ example/cmd/compat_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/example/cmd/compat.go b/example/cmd/compat.go index 5405c2d5e..7005331e9 100644 --- a/example/cmd/compat.go +++ b/example/cmd/compat.go @@ -1,6 +1,8 @@ package cmd import ( + "fmt" + "github.com/rsteube/carapace" "github.com/spf13/cobra" ) @@ -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 } diff --git a/example/cmd/compat_test.go b/example/cmd/compat_test.go index bf0777b68..2647ed948 100644 --- a/example/cmd/compat_test.go +++ b/example/cmd/compat_test.go @@ -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("")) }) }