#!/bin/bash

if [ ! -e "$1" ]
then
  echo "Usage:"
  echo "composer show foo/* >pinnings/stable"
  echo "composer show bar/* >>pinnings/stable"
  echo "$0 pinnings/stable"
  exit
fi

set -e

# We can use plain xargs here as our strings do not contain whitespace.
cat "$1" |
awk -F' +' '{printf $1":"$2; if ($3 ~ /^[0-9a-f]{7,}$/) {printf "#"$3;} print "";}'|
xargs --verbose --no-run-if-empty composer require
