diff --git a/example/cmd/root_test.go b/example/cmd/root_test.go index 8942a6d30..a94f42b5d 100644 --- a/example/cmd/root_test.go +++ b/example/cmd/root_test.go @@ -128,5 +128,11 @@ func TestRoot(t *testing.T) { Expect(carapace.ActionStyledValuesDescribed( "--array", "multiflag", style.Blue, ).NoSpace('.').Tag("flags")) + + s.Run("--toggle="). + Expect(carapace.ActionStyledValues( + "false", style.Red, + "true", style.Green, + ).Prefix("--toggle=")) }) } diff --git a/traverse.go b/traverse.go index faaa1387b..beb9970e3 100644 --- a/traverse.go +++ b/traverse.go @@ -6,6 +6,7 @@ import ( "github.com/rsteube/carapace/internal/common" "github.com/rsteube/carapace/internal/config" "github.com/rsteube/carapace/internal/pflagfork" + "github.com/rsteube/carapace/pkg/style" "github.com/spf13/cobra" ) @@ -161,7 +162,13 @@ loop: LOG.Printf("completing optional flag argument for arg %#v\n", context.CallbackValue) prefix, optarg := f.Split(context.CallbackValue) context.CallbackValue = optarg - return storage.getFlag(c, f.Name).Prefix(prefix), context + + switch f.Value.Type() { + case "bool": + return ActionValues("true", "false").StyleF(style.ForKeyword).Prefix(prefix), context + default: + return storage.getFlag(c, f.Name).Prefix(prefix), context + } } LOG.Printf("completing flags for arg %#v\n", context.CallbackValue) return actionFlags(c), context