Skip to content

Commit 31efa27

Browse files
authored
Merge pull request #3269 from carapace-sh/bazel-target
bazel: build - complete targets
2 parents b9e7bcc + 7f57893 commit 31efa27

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

completers/common/bazel_completer/cmd/build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"github.com/carapace-sh/carapace"
5+
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/bazel"
56
"github.com/spf13/cobra"
67
)
78

@@ -195,4 +196,8 @@ func init() {
195196
buildCmd.Flags().Bool("verbose_failures", false, "If a command fails, print out the full command line.")
196197
buildCmd.Flags().String("version_window_for_dirty_node_gc", "", "Nodes that have been dirty for more than this many versions will be deleted from the graph upon the next update. Values must be non-negative long integers, or -1 indicating the maximum possible window.")
197198
rootCmd.AddCommand(buildCmd)
199+
200+
carapace.Gen(buildCmd).PositionalCompletion(
201+
bazel.ActionTargets(),
202+
)
198203
}

pkg/actions/tools/bazel/target.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package bazel
2+
3+
import (
4+
"strings"
5+
6+
"github.com/carapace-sh/carapace"
7+
)
8+
9+
// ActionTargets completes targets
10+
//
11+
// //:windows_arm64
12+
// //docs:docs
13+
func ActionTargets() carapace.Action {
14+
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
15+
return carapace.ActionExecCommand("bazel", "query", "//...")(func(output []byte) carapace.Action {
16+
lines := strings.Split(string(output), "\n")
17+
vals := make([]string, 0)
18+
19+
for _, line := range lines[:len(lines)-1] {
20+
vals = append(vals, strings.TrimPrefix(line, "//"))
21+
}
22+
return carapace.ActionValues(vals...)
23+
}).MultiParts("/", ":").Prefix("//")
24+
}).Tag("targets")
25+
}

0 commit comments

Comments
 (0)