diff --git a/command.go b/command.go index 773662e..082706f 100644 --- a/command.go +++ b/command.go @@ -11,6 +11,7 @@ type Command struct { Description string `yaml:"description,omitempty" jsonschema_description:"Description of the command"` Group string `yaml:"group,omitempty" jsonschema_description:"Group of the command"` Hidden bool `yaml:"hidden,omitempty" jsonschema_description:"Hidden state of the command"` + NonInterspersed bool `yaml:"noninterspersed,omitempty" jsonschema_description:"Interspersed state of the command"` Flags map[string]string `yaml:"flags,omitempty" jsonschema_description:"Flags of the command with their description"` PersistentFlags map[string]string `yaml:"persistentflags,omitempty" jsonschema_description:"Persistent flags of the command with their description"` ExclusiveFlags [][]string `yaml:"exclusiveflags,omitempty" jsonschema_description:"Flags that are mutually exclusive"` @@ -51,6 +52,8 @@ func (c Command) ToCobraE() (*cobra.Command, error) { Hidden: c.Hidden, Run: func(cmd *cobra.Command, args []string) {}, } + cmd.Flags().SetInterspersed(!c.NonInterspersed) + carapace.Gen(cmd).Standalone() for _, f := range []func(cmd *cobra.Command) error{ diff --git a/command_test.go b/command_test.go new file mode 100644 index 0000000..cb61721 --- /dev/null +++ b/command_test.go @@ -0,0 +1,34 @@ +package spec + +import ( + _ "embed" + "testing" + + "github.com/rsteube/carapace" + "github.com/rsteube/carapace/pkg/sandbox" + "github.com/rsteube/carapace/pkg/style" +) + +//go:embed example/interspersed.yaml +var interspersedSpec string + +func TestInterspersed(t *testing.T) { + sandboxSpec(t, interspersedSpec)(func(s *sandbox.Sandbox) { + s.Run("--bool", ""). + Expect(carapace.ActionValues( + "four", + "five", + "six", + )) + + s.Run("--bool", "-"). + Expect(carapace.ActionStyledValuesDescribed( + "--string", "string flag", style.Blue, + ).NoSpace('.'). + Tag("flags")) + + s.Run("--bool", "four", "-"). + Expect(carapace.ActionValues()) + + }) +} diff --git a/example/interspersed.yaml b/example/interspersed.yaml new file mode 100644 index 0000000..d72e6f6 --- /dev/null +++ b/example/interspersed.yaml @@ -0,0 +1,9 @@ +name: interspersed +noninterspersed: true +flags: + --bool: bool flag + --string=: string flag +completion: + flag: + string: ["one", "two", "three"] + positionalany: ["four", "five", "six"]