Skip to content

Instantly share code, notes, and snippets.

@philwo
Created August 5, 2019 11:50
Show Gist options
  • Save philwo/c4aa06a851c775731474417546f0a6a3 to your computer and use it in GitHub Desktop.
Save philwo/c4aa06a851c775731474417546f0a6a3 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
unset IFS
args=()
found="no"
function add_env_flags() {
# Add an --action_env=$ENV flag for every environment variable.
for var in $(compgen -e); do
args+=("--action_env=$var")
done
}
# Add all args from the command-line to the array.
for arg in "$@"; do
# Bazel uses the "--" to split flags and target names, so if it's present in the command-line
# args, we have to insert our flags before that separator.
if [[ $arg == "--" ]]; then
add_env_flags
found="yes"
fi
args+=("$arg")
done
# If there was no "--" separator, just add the --action_env= flags to the end of the command-line.
if [[ $found == "no" ]]; then
add_env_flags
fi
exec bazel "${args[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment