Repository: rsteube/carapace (go)

Issue:
flag completion for embedded dash command broken
```sh
example action -- --<TAB> # no results
example action -- -<TAB> # completes longhand flags
```

Pull request:
fix dash completion
fix #710

Patch:
diff --git a/example/cmd/action.go b/example/cmd/action.go
index 821ce17..ab58d91 100644
--- a/example/cmd/action.go
+++ b/example/cmd/action.go
@@ -145,7 +145,16 @@ func init() {
 				Run: func(cmd *cobra.Command, args []string) {},
 			}
 
-			cmd.Flags().Bool("embedded-flag", false, "embedded flag")
+			cmd.Flags().Bool("embedded-bool", false, "embedded bool flag")
+			cmd.Flags().String("embedded-string", "", "embedded string flag")
+			cmd.Flags().String("embedded-optarg", "", "embedded optarg flag")
+
+			cmd.Flag("embedded-optarg").NoOptDefVal = " "
+
+			carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
+				"embedded-string": carapace.ActionValues("es1", "es2", "es3"),
+				"embedded-optarg": carapace.ActionValues("eo1", "eo2", "eo3"),
+			})
 
 			carapace.Gen(cmd).PositionalCompletion(
 				carapace.ActionValues("embeddedPositional1", "embeddedP1"),
diff --git a/traverse.go b/traverse.go
index b18d8e1..6b6bf0b 100644
--- a/traverse.go
+++ b/traverse.go
@@ -63,7 +63,7 @@ loop:
 		// dash
 		case arg == "--":
 			logger.Printf("arg %#v is dash\n", arg)
-			inArgs = append(inArgs, args[i:]...)
+			inArgs = append(inArgs, context.Args[i:]...)
 			break loop
 
 		// flag
@@ -74,6 +74,10 @@ loop:
 				Flag: fs.LookupArg(arg),
 				Args: []string{},
 			}
+
+			if inFlag.Flag == nil {
+				logger.Printf("flag %#v is unknown", arg)
+			}
 			continue
 
 		// subcommand
@@ -137,7 +141,9 @@ loop:
 	// dash argument
 	case common.IsDash(c):
 		logger.Printf("completing dash for arg %#v\n", context.CallbackValue)
-		context.Args = c.Flags().Args()[c.ArgsLenAtDash()+1:]
+		context.Args = c.Flags().Args()[c.ArgsLenAtDash():]
+		logger.Printf("context: %#v\n", context.Args)
+
 		return storage.getPositional(c, len(context.Args)), context
 
 	// flag argument


Test patch:
diff --git a/example/cmd/action_test.go b/example/cmd/action_test.go
index c7a213c..7b64707 100644
--- a/example/cmd/action_test.go
+++ b/example/cmd/action_test.go
@@ -171,18 +171,35 @@ func TestDash(t *testing.T) {
 				Usage("action [pos1] [pos2] [--] [dashAny]..."))
 
 		s.Run("action", "--", "-").
-			Expect(carapace.ActionValuesDescribed(
-				"--embedded-flag", "embedded flag").
+			Expect(carapace.ActionStyledValuesDescribed(
+				"--embedded-bool", "embedded bool flag", style.Default,
+				"--embedded-optarg", "embedded optarg flag", style.Yellow,
+				"--embedded-string", "embedded string flag", style.Blue).
 				NoSpace('.').
 				Usage("action [pos1] [pos2] [--] [dashAny]...").
 				Tag("flags"))
 
 		s.Run("action", "--", "--").
-			Expect(carapace.ActionValuesDescribed(
-				"--embedded-flag", "embedded flag").
+			Expect(carapace.ActionStyledValuesDescribed(
+				"--embedded-bool", "embedded bool flag", style.Default,
+				"--embedded-optarg", "embedded optarg flag", style.Yellow,
+				"--embedded-string", "embedded string flag", style.Blue).
 				NoSpace('.').
 				Usage("action [pos1] [pos2] [--] [dashAny]...").
 				Tag("flags"))
+
+		s.Run("action", "--", "embeddedP1", "--embedded-optarg=").
+			Expect(carapace.ActionValues("eo1", "eo2", "eo3").
+				Prefix("--embedded-optarg=").
+				Usage("embedded optarg flag"))
+
+		s.Run("action", "--", "embeddedP1", "--embedded-string", "").
+			Expect(carapace.ActionValues("es1", "es2", "es3").
+				Usage("embedded string flag"))
+
+		s.Run("action", "p1", "--styled-values", "second", "p2", "--", "embeddedP1", "--embedded-string", "es1", "").
+			Expect(carapace.ActionValues("embeddedPositional2", "embeddedP2").
+				Usage("action [pos1] [pos2] [--] [dashAny]..."))
 	})
 }