Skip to content

Commit

Permalink
Merge pull request #527 from rsteube/use-batch
Browse files Browse the repository at this point in the history
use `carapace.Batch` for better performance
  • Loading branch information
rsteube authored Aug 9, 2021
2 parents 6477dce + 02e1f07 commit 6564c9f
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 40 deletions.
7 changes: 4 additions & 3 deletions completers/cfdisk_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ func init() {

func ActionBlockDevicesAndFiles() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
blockDevices := fs.ActionBlockDevices().Invoke(c)
files := carapace.ActionFiles().Invoke(c)
return blockDevices.Merge(files).ToA()
return carapace.Batch(
fs.ActionBlockDevices(),
carapace.ActionFiles(),
).Invoke(c).Merge().ToA()
})
}
7 changes: 4 additions & 3 deletions completers/fdisk_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ func init() {

func ActionBlockDevicesAndFiles() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
blockDevices := fs.ActionBlockDevices().Invoke(c)
files := carapace.ActionFiles().Invoke(c)
return blockDevices.Merge(files).ToA()
return carapace.Batch(
fs.ActionBlockDevices(),
carapace.ActionFiles(),
).Invoke(c).Merge().ToA()
})
}
7 changes: 4 additions & 3 deletions completers/flutter_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ func init() {

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"device-id": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
devices := action.ActionDevices().Invoke(c)
emulators := action.ActionEmulators().Invoke(c)
return devices.Merge(emulators).ToA()
return carapace.Batch(
action.ActionDevices(),
action.ActionEmulators(),
).Invoke(c).Merge().ToA()
}),
})
}
7 changes: 4 additions & 3 deletions completers/gh_completer/cmd/pr_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ func init() {

carapace.Gen(pr_checksCmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
pullRequests := action.ActionPullRequests(pr_checksCmd, action.PullRequestOpts{Open: true}).Invoke(c)
branches := action.ActionBranches(pr_checksCmd).Invoke(c)
return pullRequests.Merge(branches).ToA()
return carapace.Batch(
action.ActionPullRequests(pr_checksCmd, action.PullRequestOpts{Open: true}),
action.ActionBranches(pr_checksCmd),
).Invoke(c).Merge().ToA()
}),
)
}
7 changes: 4 additions & 3 deletions completers/glab_completer/cmd/action/mergeRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ func ActionMergeRequests(cmd *cobra.Command, state string) carapace.Action {

func ActionMergeRequestsAndBranches(cmd *cobra.Command, state string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
branches := ActionBranches(cmd).Invoke(c)
mergeRequests := ActionMergeRequests(cmd, state).Invoke(c)
return branches.Merge(mergeRequests).Filter(c.Args).ToA()
return carapace.Batch(
ActionBranches(cmd),
ActionMergeRequests(cmd, state),
).Invoke(c).Merge().ToA()
})
}
19 changes: 10 additions & 9 deletions completers/glab_completer/cmd/action/repoOverride.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ func ActionRepo(cmd *cobra.Command) carapace.Action {
case 0:
return carapace.ActionValues(configHosts...).Invoke(c).Suffix("/").ToA()
case 1:
// TODO goroutine
users := ActionUsers(cmd).Invoke(c).Suffix("/")
groups := ActionGroups(cmd).Invoke(c).Suffix("/")
return users.Merge(groups).ToA()
return carapace.Batch(
ActionUsers(cmd),
ActionGroups(cmd),
).Invoke(c).Merge().Suffix("/").ToA()
case 2:
// TODO goroutine
subgroups := ActionSubgroups(cmd, c.Parts[1]).Invoke(c).Suffix("/")
groupProjects := ActionGroupProjects(cmd, c.Parts[1]).Invoke(c)
userProjects := ActionUserProjects(cmd, c.Parts[1]).Invoke(c)
return subgroups.Merge(groupProjects, userProjects).ToA()
b := carapace.Batch(
ActionSubgroups(cmd, c.Parts[1]),
ActionGroupProjects(cmd, c.Parts[1]),
ActionUserProjects(cmd, c.Parts[1]),
).Invoke(c)
return b[0].Suffix("/").Merge(b[1:]...).ToA() // ActionSubgroups needs `/` suffix
case 3:
groupProjects := ActionGroupProjects(cmd, strings.Join(c.Parts[1:], "/")).Invoke(c)
return groupProjects.ToA()
Expand Down
7 changes: 4 additions & 3 deletions completers/glab_completer/cmd/repo_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ func init() {
carapace.Gen(repo_archiveCmd).FlagCompletion(carapace.ActionMap{
"format": carapace.ActionValues("tar.gz", "tar.bz2", "tbz", "tbz2", "tb2", "bz2", "tar", "zip"),
"sha": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
branches := action.ActionBranches(repo_archiveCmd).Invoke(c)
tags := action.ActionTags(repo_archiveCmd).Invoke(c)
return branches.Merge(tags).ToA() // TODO sha
return carapace.Batch(
action.ActionBranches(repo_archiveCmd),
action.ActionTags(repo_archiveCmd),
).Invoke(c).Merge().ToA() // TODO sha
}),
})

Expand Down
7 changes: 3 additions & 4 deletions completers/java_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,13 @@ func ActionClasspathClasses(cmd *cobra.Command) carapace.Action {
}
}

actions := carapace.ActionValues().Invoke(c)
actions := make([]carapace.Action, 0)
for _, file := range files {
if strings.HasSuffix(file, ".jar") ||
strings.HasSuffix(file, ".zip") {
a := action.ActionJarFileClasses(file)
actions = actions.Merge(a.Invoke(c))
actions = append(actions, action.ActionJarFileClasses(file))
}
}
return actions.ToMultiPartsA(".")
return carapace.Batch(actions...).Invoke(c).Merge().ToMultiPartsA(".")
})
}
7 changes: 4 additions & 3 deletions completers/kill_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ func init() {

func actionProcessIdsAndNames() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
pids := os.ActionProcessIds().Invoke(c)
names := os.ActionProcessExecutables().Invoke(c)
return pids.Merge(names).Filter(c.Args).ToA()
return carapace.Batch(
os.ActionProcessIds(),
os.ActionProcessExecutables(),
).Invoke(c).Merge().Filter(c.Args).ToA()
})
}
7 changes: 4 additions & 3 deletions completers/pandoc_completer/cmd/action/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ func extensionFields(s string) []string {

func ActionFormats() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
input := ActionInputFormats().Invoke(c)
output := ActionOutputFormats().Invoke(c)
return input.Merge(output).ToA()
return carapace.Batch(
ActionInputFormats(),
ActionOutputFormats(),
).Invoke(c).Merge().ToA()
})
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/go-ps v1.0.0
github.com/pelletier/go-toml v1.8.1
github.com/rsteube/carapace v0.7.1
github.com/rsteube/carapace v0.8.0
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rsteube/carapace v0.7.1 h1:HfD0MgX8HtrhEqfodE+XAWogAF35UdisWxDiblLi7bA=
github.com/rsteube/carapace v0.7.1/go.mod h1:Vo7qSmFjuOTjB3cEyyat0+ANvVHlS0HR4NhIdAN07vM=
github.com/rsteube/carapace v0.8.0 h1:OVTWIqLmE9qskAtFOIvYvDNmB+6fL3Ovxe5y78iBXQ8=
github.com/rsteube/carapace v0.8.0/go.mod h1:Vo7qSmFjuOTjB3cEyyat0+ANvVHlS0HR4NhIdAN07vM=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
Expand Down

0 comments on commit 6564c9f

Please sign in to comment.