Skip to content

Commit

Permalink
actionFlags: multipart completion for flags as default
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 13, 2023
1 parent 8392d9c commit 97fe535
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
12 changes: 6 additions & 6 deletions example/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,33 @@ func TestRoot(t *testing.T) {
"-p", "Help message for persistentFlag",
"--toggle", "Help message for toggle",
"-t", "Help message for toggle",
).Tag("flags"))
).NoSpace('.').Tag("flags"))

s.Run("--").
Expect(carapace.ActionValuesDescribed(
"--array", "multiflag",
"--persistentFlag", "Help message for persistentFlag",
"--toggle", "Help message for toggle",
).Tag("flags"))
).NoSpace('.').Tag("flags"))

s.Run("--a").
Expect(carapace.ActionValuesDescribed(
"--array", "multiflag",
).Tag("flags"))
).NoSpace('.').Tag("flags"))

s.Run("--array").
Expect(carapace.ActionValuesDescribed(
"--array", "multiflag",
).Tag("flags"))
).NoSpace('.').Tag("flags"))

s.Run("--array", "", "--a").
Expect(carapace.ActionValuesDescribed(
"--array", "multiflag",
).Tag("flags"))
).NoSpace('.').Tag("flags"))

s.Run("-a", "", "--a").
Expect(carapace.ActionValuesDescribed(
"--array", "multiflag",
).Tag("flags"))
).NoSpace('.').Tag("flags"))
})
}
7 changes: 1 addition & 6 deletions internalActions.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,7 @@ func actionFlags(cmd *cobra.Command) Action {
if isShorthandSeries {
return ActionValuesDescribed(vals...).Invoke(c).Prefix(c.CallbackValue).ToA().NoSpace('*')
}
for i := 0; i < len(vals); i = i + 2 { // TODO experimental - hardcoded multiparts completion if flags are "grouped" with `.`
if strings.Contains(vals[i], ".") {
return ActionValuesDescribed(vals...).Invoke(c).ToMultiPartsA(".")
}
}
return ActionValuesDescribed(vals...)
return ActionValuesDescribed(vals...).Invoke(c).ToMultiPartsA(".") // multiparts completion for flags grouped with `.`
}).Tag("flags")
}

Expand Down

0 comments on commit 97fe535

Please sign in to comment.