#!/bin/bash
#
# Run scripts with hg-dev environment. Examples:
#
#   with-hg-dev ./lint.py
#   with-hg-dev ./unit.py
#
# Exit 40 if hg-dev cannot be found, or does not have desired effect.

SCRIPT_PATH="${BASH_SOURCE[0]:-$0}"
builtin cd $(dirname "$SCRIPT_PATH")

if [[ -z $HG_DEV_DIR ]]; then
  for path in ../../hg-dev ${HG_RPM_DIR:-~/facebook-hg-rpms/hg-dev}; do
    if [[ -f "$path" ]]; then
      source "$path"
      break
    fi
  done
  if [[ -z $HG_DEV_DIR ]]; then
    echo abort: cannot find hg-dev 1>&2
    exit 40
  fi
fi

command $@
