Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ The bazel completion scripts are taken from installer binaries. If you use a
custom base URL, make sure the installer URLs are available alongside with
bazel binaries.

#### Disabling Bazelisk's completion handler

If the underlying Bazel binary provides its own `completion` command with
broader shell support (e.g. zsh), you can disable Bazelisk's built-in
completion handling so that the command is passed through to the underlying
binary. Set `BAZELISK_DISABLE_COMPLETION` in your `.bazeliskrc`:

```shell
BAZELISK_DISABLE_COMPLETION=1
```

### Useful environment variables for --migrate and --bisect

You can set `BAZELISK_INCOMPATIBLE_FLAGS` to set a list of incompatible flags (separated by `,`) to be tested, otherwise Bazelisk tests all flags starting with `--incompatible_`.
Expand Down Expand Up @@ -259,6 +270,7 @@ The following variables can be set:
- `BAZELISK_FORMAT_URL`
- `BAZELISK_NOJDK`
- `BAZELISK_CLEAN`
- `BAZELISK_DISABLE_COMPLETION`
- `BAZELISK_GITHUB_TOKEN`
- `BAZELISK_HOME_DARWIN`
- `BAZELISK_HOME_LINUX`
Expand Down
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func RunBazeliskWithArgsFuncAndConfigAndOutAndErr(argsFunc ArgsFunc, repos *Repo
}

// handle completion command
if isCompletionCommand(args) {
if isCompletionCommand(args) && config.Get("BAZELISK_DISABLE_COMPLETION") == "" {
err := handleCompletionCommand(args, bazelInstallation, config)
if err != nil {
if errors.Is(err, httputil.NotFound) {
Expand Down
53 changes: 53 additions & 0 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,59 @@ func TestIsCompletionCommand(t *testing.T) {
}
}

func TestDisableCompletionConfig(t *testing.T) {
testCases := []struct {
name string
args []string
configValue string
shouldIntercept bool
}{
{
name: "completion intercepted by default",
args: []string{"completion", "bash"},
configValue: "",
shouldIntercept: true,
},
{
name: "completion disabled with config",
args: []string{"completion", "bash"},
configValue: "1",
shouldIntercept: false,
},
{
name: "completion disabled with any non-empty value",
args: []string{"completion", "zsh"},
configValue: "true",
shouldIntercept: false,
},
{
name: "non-completion command unaffected",
args: []string{"build", "//..."},
configValue: "",
shouldIntercept: false,
},
{
name: "non-completion command unaffected with config",
args: []string{"build", "//..."},
configValue: "1",
shouldIntercept: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cfg := config.Static(map[string]string{
"BAZELISK_DISABLE_COMPLETION": tc.configValue,
})
result := isCompletionCommand(tc.args) && cfg.Get("BAZELISK_DISABLE_COMPLETION") == ""
if result != tc.shouldIntercept {
t.Errorf("completion interception for args=%v, BAZELISK_DISABLE_COMPLETION=%q: got %v, want %v",
tc.args, tc.configValue, result, tc.shouldIntercept)
}
})
}
}

func TestConstructInstallerURL(t *testing.T) {
testCases := []struct {
name string
Expand Down