#!/bin/bash

ARGS=("$@")

set -eo pipefail {0}

if command -v ex_doc &> /dev/null; then
   exec ex_doc "${ARGS[@]}"
else
    echo -n "Could not find ex_doc! "
    read -p "Do you want to download latest ex_doc from github? (y/n)? " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        if $ERL_TOP/otp_build download_ex_doc; then
            read -p "Press any key to continue..." -n 1 -r
            echo "continuing"
            exec ex_doc "${ARGS[@]}"
        else
            exit 1
        fi
    else
        exit 1
    fi
fi
