#!/usr/bin/env bash set -euo pipefail usage() { cat <<'EOF' Usage: plugin validate plugin test [mix test args...] plugin precommit [mix precommit args...] plugin shell EOF } fail() { echo "plugin: $*" >&2 exit 1 } script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" plugin_root="$(cd "$script_dir/.." && pwd -P)" host_root="${TRIBES_HOST_ROOT:-$plugin_root/../tribes}" host_root="$(cd "$host_root" && pwd -P)" host_script="$host_root/scripts/plugin" command_name="${1:-}" if [[ -z "$command_name" ]]; then usage exit 1 fi shift case "$command_name" in validate | test | precommit | shell) ;; -h | --help | help) usage exit 0 ;; *) usage fail "unknown command: $command_name" ;; esac [[ -x "$host_script" || -f "$host_script" ]] || fail "expected host plugin script at $host_script" if [[ "${DEVENV_ROOT:-}" == "$plugin_root" ]]; then command -v devenv >/dev/null 2>&1 || fail "devenv is required when running from the plugin devenv shell" cd "$host_root" exec devenv shell -- bash ./scripts/plugin "$command_name" "$plugin_root" "$@" fi exec bash "$host_script" "$command_name" "$plugin_root" "$@"