#!/bin/sh

# Shift process name parameter out.
shift

tmpfile=$(mktemp /tmp/cargo-flow.XXXXXX)
result="$(cargo $@ --color always 2>&1)"

if [ "$?" -ne 0 ]; then
	# Display the results, but also output them to `errors.err`, which vim
	# can read, after stripping any ANSI escape sequences.
	echo -n "$result" | tee $tmpfile
	sed -r 's/\x1b\[[0-9;]*m?//g' $tmpfile > errors.err
else
	echo "$result"
	echo -n > errors.err
fi
