Skip to content

Commit

Permalink
support interspersed
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Aug 30, 2023
1 parent ed3b894 commit 88c31c6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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{
Expand Down
34 changes: 34 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
@@ -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())

})
}
9 changes: 9 additions & 0 deletions example/interspersed.yaml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 88c31c6

Please sign in to comment.