#!/bin/sh

# Wrapper to execute an external tool. This is used a bit like "go tool", but in
# a case we don't want to put the dependency in go.mod (which may be considered
# by an anti-pattern for some tools).

# See commit 414d626bf8f2 for an alternative.

cmd="$1"
shift

GO=${GO:-go}
export GOTOOLCHAIN=$(${GO} mod edit -print | sed -En 's/^toolchain //p')

case "$cmd" in
    buf)
        exec ${GO} run github.com/bufbuild/buf/cmd/buf@v1.57.0 "$@"
        ;;
esac
