## Generate updated output file from given command's stdout:
#
# do_update $out $BIN/cmd --args
#
# Writes output to a temporary .new file, optionally shows a diff of changes, and commits
# the new version to $out (unless noop'd).
function cmd_apply {
local out="$1"
local tmp="$out.new"
debug "$out"
cmd "${@:1}" > "$tmp"
# compare
if [ -e "$out" -a -z "$APPLY_DIFF" ]; then
debug " changes:"
# terse
indent " " diff --unified=1 "$out" "$tmp" || true
fi
# deploy
if [ "$APPLY" = 0 ]; then
# cleanup
debug " no-op"
cmd rm "$tmp"
else
# commit
debug " deploy"
cmd mv "$tmp" "$out"
fi
}