set -u
record="${TIX_FAKE_RECORD:?TIX_FAKE_RECORD must be set for the fake linear-cli}"
echo "linear-cli $*" >> "$record"
echo "LINEAR_API_KEY=${LINEAR_API_KEY:-}" >> "$record"
if [ "${TIX_FAKE_FAIL:-}" != "" ]; then
echo "LEAK:LINEAR_API_KEY=${LINEAR_API_KEY:-}" >&2
exit "${TIX_FAKE_FAIL}"
fi
check_argv() {
local saw_dd=0 a
while [ $# -gt 0 ]; do
a="$1"
if [ "$saw_dd" = 1 ]; then shift; continue; fi
if [ "$a" = "--" ]; then saw_dd=1; shift; continue; fi
case "$a" in
-[a-zA-Z]=* | --*=*) shift; continue ;;
esac
case "$a" in
-t | -d | -l | -p | -s | -T | -r | -o | --output | -a | -e | --limit | --filter | --project | --assignee | --state | --team | --labels | --description | --priority | --title)
shift
if [ $# -eq 0 ] || [ "${1#-}" != "$1" ]; then
echo "error: unexpected argument '${1:-}' found" >&2
return 2
fi
shift
;;
-*) echo "error: unexpected argument '$a' found" >&2; return 2 ;;
*) shift ;;
esac
done
return 0
}
sub="${1:-}"; shift 2>/dev/null || true
case "$sub" in
issues)
sub2="${1:-}"; shift 2>/dev/null || true
check_argv "$@" || exit 2
case "$sub2" in
create)
count=$(grep -c "linear-cli issues create" "$record" 2>/dev/null || echo 1)
id=$((99 + count))
printf '{"identifier": "ENG-%d", "url": "https://linear.app/acme/issue/ENG-%d"}\n' "$id" "$id"
;;
update)
echo ""
;;
get)
if [ -n "${TIX_FAKE_GET:-}" ]; then
printf '%s\n' "$TIX_FAKE_GET"
else
printf '{}\n'
fi
;;
list)
printf '%s\n' "${TIX_FAKE_LIST:-[]}"
;;
*)
echo "unknown linear-cli issues subcommand: $sub2" >&2
exit 2
;;
esac
;;
relations)
sub2="${1:-}"; shift 2>/dev/null || true
check_argv "$@" || exit 2
case "$sub2" in
add)
echo ""
;;
list)
printf '%s\n' "${TIX_FAKE_LIST:-[]}"
;;
remove)
echo ""
;;
*)
echo "unknown linear-cli relations subcommand: $sub2" >&2
exit 2
;;
esac
;;
*)
echo "unknown linear-cli subcommand: $sub" >&2
exit 2
;;
esac
exit 0