#!/bin/sh

if [ "$1" == "" ]; then
	echo "  Usage: pull-images-from <stack-name>"
	exit 1
fi

function pull_images_from {
    images=($(images-from $1))
    length=${#images[@]}
    pullCommand=''

    for (( i=0; i<${length}; i++ ));
    do
      if [ $i == $[${length} - 1] ]; then
        pullCommand+=" docker pull ${images[i]}"
      else
        pullCommand+=" docker pull ${images[i]} &&"
      fi
    done

    eval $pullCommand
}

pull_images_from $1

