#!/usr/bin/env sh

if [ "$#" -lt "1" ]; then
  echo "You should pass at least 1 parameter to pnpm" 1>&2
  pnpm-install --help
  exit 1
fi

cmd=$1
shift $(( $# > 0 ? 1 : 0 ))
args=$*

case $cmd in
  h | help | -h | --help)
    shift $(( $# > 0 ? 1 : 0 ))
    cmd=$args
    args=--help
    ;;
  -v | --version)
    cmd=install
    args=--version
    ;;
esac

case $cmd in
  i)
    cmd=install
    ;;
esac

if which pnpm-${cmd} 2>&1 >/dev/null; then
  pnpm-${cmd} $args
else
  npm ${cmd} $args
fi
