From 24651abd7c833829b585373cd540a30cd98e7dfd Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 18 Apr 2024 15:51:01 +0100 Subject: [PATCH] Allow specifying where stdout should get written (#526) This can be useful when invoking bazelisk programatically. --- core/core.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/core.go b/core/core.go index 4b372db8..429ae324 100644 --- a/core/core.go +++ b/core/core.go @@ -89,6 +89,12 @@ func RunBazeliskWithArgsFunc(argsFunc ArgsFunc, repos *Repositories) (int, error // RunBazeliskWithArgsFuncAndConfig runs the main Bazelisk logic for the given ArgsFunc and Bazel // repositories and config. func RunBazeliskWithArgsFuncAndConfig(argsFunc ArgsFunc, repos *Repositories, config config.Config) (int, error) { + return RunBazeliskWithArgsFuncAndConfigAndOut(argsFunc, repos, config, nil) +} + +// RunBazeliskWithArgsFuncAndConfigAndOut runs the main Bazelisk logic for the given ArgsFunc and Bazel +// repositories and config, writing its stdout to the passed writer. +func RunBazeliskWithArgsFuncAndConfigAndOut(argsFunc ArgsFunc, repos *Repositories, config config.Config, out io.Writer) (int, error) { httputil.UserAgent = getUserAgent(config) bazeliskHome := config.Get("BAZELISK_HOME") @@ -198,7 +204,7 @@ func RunBazeliskWithArgsFuncAndConfig(argsFunc ArgsFunc, repos *Repositories, co } } - exitCode, err := runBazel(bazelPath, args, nil, config) + exitCode, err := runBazel(bazelPath, args, out, config) if err != nil { return -1, fmt.Errorf("could not run Bazel: %v", err) }