Repository: rsteube/carapace (go)

Issue:
DisableFlagParsing: positional completion is repeated
### Current Behavior

Positional completion gets repeated when flag parsing is disabled:

```sh
example disabled p1 p2 po<TAB>
# positional1
```

### Expected Behavior

Nothing should be completed  on the third position.

### Steps To Reproduce

_No response_

### Version

0.47.2

### OS

- [X] Linux
- [ ] OSX
- [ ] Windows

### Shell

- [ ] Bash
- [x] Elvish
- [ ] Fish
- [ ] Nushell
- [ ] Oil
- [ ] Powershell
- [ ] Xonsh
- [ ] Zsh

### Anything else?

```go
package cmd

import (
	"github.com/rsteube/carapace"
	"github.com/spf13/cobra"
)

var disabledCmd = &cobra.Command{
	Use:                "disabled",
	Short:              "",
	DisableFlagParsing: true,
	Run:                func(cmd *cobra.Command, args []string) {},
}

func init() {
	carapace.Gen(disabledCmd).Standalone()

	rootCmd.AddCommand(disabledCmd)

	carapace.Gen(disabledCmd).PositionalCompletion(
		carapace.ActionValues("p1", "positional1"),
		carapace.ActionValues("p2", "positional2"),
	)
}
```

Pull request:
FlagParsingDisabled: fix positional completion
fix #962

Patch:
diff --git a/defaultActions.go b/defaultActions.go
index 2d1df6a..dc7d28c 100644
--- a/defaultActions.go
+++ b/defaultActions.go
@@ -529,7 +529,11 @@ func ActionCobra(f func(cmd *cobra.Command, args []string, toComplete string) ([
 			LOG.Print("cmd is nil [ActionCobra]")
 			c.cmd = &cobra.Command{Use: "_carapace_actioncobra", Hidden: true, Deprecated: "dummy command for ActionCobra"}
 		}
-		values, directive := f(c.cmd, c.cmd.Flags().Args(), c.Value)
+
+		if !c.cmd.DisableFlagParsing {
+			c.Args = c.cmd.Flags().Args()
+		}
+		values, directive := f(c.cmd, c.Args, c.Value)
 		return compDirective(directive).ToA(values...)
 	})
 }
diff --git a/example/cmd/flag_disabled.go b/example/cmd/flag_disabled.go
new file mode 100644
index 0000000..1ba89e9
--- /dev/null
+++ b/example/cmd/flag_disabled.go
@@ -0,0 +1,24 @@
+package cmd
+
+import (
+	"github.com/rsteube/carapace"
+	"github.com/spf13/cobra"
+)
+
+var flag_disabledCmd = &cobra.Command{
+	Use:                "disabled",
+	Short:              "flag parsing disabled",
+	DisableFlagParsing: true,
+	Run:                func(cmd *cobra.Command, args []string) {},
+}
+
+func init() {
+	carapace.Gen(flag_disabledCmd).Standalone()
+
+	flagCmd.AddCommand(flag_disabledCmd)
+
+	carapace.Gen(flag_disabledCmd).PositionalCompletion(
+		carapace.ActionValues("-p1", "positional1"),
+		carapace.ActionValues("p2", "--positional2"),
+	)
+}


Test patch:
diff --git a/example/cmd/flag_disabled_test.go b/example/cmd/flag_disabled_test.go
new file mode 100644
index 0000000..b413afc
--- /dev/null
+++ b/example/cmd/flag_disabled_test.go
@@ -0,0 +1,27 @@
+package cmd
+
+import (
+	"testing"
+
+	"github.com/rsteube/carapace"
+	"github.com/rsteube/carapace/pkg/sandbox"
+)
+
+func TestFlagDisabled(t *testing.T) {
+	sandbox.Package(t, "github.com/rsteube/carapace/example")(func(s *sandbox.Sandbox) {
+		s.Run("flag", "disabled", "").
+			Expect(carapace.ActionValues(
+				"-p1",
+				"positional1",
+			))
+
+		s.Run("flag", "disabled", "-p1", "").
+			Expect(carapace.ActionValues(
+				"p2",
+				"--positional2",
+			))
+
+		s.Run("flag", "disabled", "-p1", "p2", "").
+			Expect(carapace.ActionValues())
+	})
+}