#!/bin/bash
# Run CI_report_dashboard_planet.Rmd
# Usage: ./05_run_dashboard_report.sh --filename=<output.html> --report_date=<YYYY-MM-DD> --mail_day=<day> --data_dir=kibos --borders=TRUE

filename="dashboard_report.html"
report_date="$(date +%Y-%m-%d)"
mail_day="Monday"
data_dir="kibos"
borders="TRUE"

for arg in "$@"; do
    case $arg in
        --filename=*)
            filename="${arg#*=}"
            ;;
        --report_date=*)
            report_date="${arg#*=}"
            ;;
        --mail_day=*)
            mail_day="${arg#*=}"
            ;;
        --data_dir=*)
            data_dir="${arg#*=}"
            ;;
        --borders=*)
            borders="${arg#*=}"
            ;;
        *)
            echo "Unknown option: $arg"
            exit 1
            ;;
    esac
    shift
done

echo "Running CI_report_dashboard_planet.Rmd for $data_dir, report date $report_date, mail day $mail_day, borders $borders."
cd r_app
Rscript -e "rmarkdown::render('05_CI_report_dashboard_planet.Rmd', output_file='$filename', params=list(report_date='$report_date', mail_day='$mail_day', data_dir='$data_dir', borders='$borders'))"
cd ..
