Skip to content

Commit

Permalink
Merge pull request #1034 from rsteube/go-fix-delimiter
Browse files Browse the repository at this point in the history
go: test - fix delimiter
  • Loading branch information
rsteube authored Apr 11, 2022
2 parents 6d1d9e9 + 85766cb commit fee8191
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 8 additions & 5 deletions completers/go_completer/cmd/action/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
)

type TestOpts struct {
Expand All @@ -17,12 +18,14 @@ func ActionTests(packages []string, opts TestOpts) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)
for _, line := range lines {
if (opts.Benchmark && strings.HasPrefix(line, "Benchmark")) ||
(opts.Example && strings.HasPrefix(line, "Example")) ||
(opts.Test && strings.HasPrefix(line, "Test")) {
vals = append(vals, line)
if opts.Benchmark && strings.HasPrefix(line, "Benchmark") {
vals = append(vals, line, style.Blue)
} else if opts.Example && strings.HasPrefix(line, "Example") {
vals = append(vals, line, style.Green)
} else if opts.Test && strings.HasPrefix(line, "Test") {
vals = append(vals, line, style.Default)
}
}
return carapace.ActionValues(vals...)
return carapace.ActionStyledValues(vals...)
})
}
7 changes: 2 additions & 5 deletions completers/go_completer/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,12 @@ func init() {
testCmd.Flags().String("vet", "", "configure the invocation of \"go vet\" during \"go test\" to use the comma-separated list of vet check")
rootCmd.AddCommand(testCmd)

testCmd.Flag("bench").NoOptDefVal = " "
testCmd.Flag("run").NoOptDefVal = " "

carapace.Gen(testCmd).FlagCompletion(carapace.ActionMap{
"bench": carapace.ActionMultiParts("/", func(c carapace.Context) carapace.Action {
"bench": carapace.ActionMultiParts("|", func(c carapace.Context) carapace.Action {
return action.ActionTests(c.Args, action.TestOpts{Benchmark: true}).Invoke(c).Filter(c.Parts).ToA()
}),
"covermode": carapace.ActionValues("set", "count,atomic"),
"run": carapace.ActionMultiParts("/", func(c carapace.Context) carapace.Action {
"run": carapace.ActionMultiParts("|", func(c carapace.Context) carapace.Action {
return action.ActionTests(c.Args, action.TestOpts{Example: true, Test: true}).Invoke(c).Filter(c.Parts).ToA()
}),
})
Expand Down

0 comments on commit fee8191

Please sign in to comment.