stdenv/setup: make substituteInPlace require actual files

I've often run into substituteInPlace doing nothing when I invoked it
wrong, like:

substituteInPlace --replace-fail from to file.txt

The substitute function would pass file.txt on to substituteStream,
which complain about the extraneous argument. However, if no files are
passed, substitute is never called and substituteInPlace silently does
nothing.

It would be more annoying to make substituteInPlace accept file
arguments anywhere (since it would need to understand the arguments to
substituteStream), so let's error on this incorrect usage instead.

Change-Id: Ib2daad6f49bbe516a273a35d7f2a31fc42fd053c
This commit is contained in:
Linus Heckemann 2024-09-29 18:37:00 +02:00
parent d4d77ce350
commit 9767bb9bf1

View File

@ -1073,6 +1073,10 @@ substituteInPlace() {
fileNames+=("$arg")
shift
done
if ! [[ "${#fileNames[@]}" -gt 0 ]]; then
echo >&2 "substituteInPlace called without any files to operate on (files must come before options!)"
return 1
fi
for file in "${fileNames[@]}"; do
substitute "$file" "$file" "$@"