#!/bin/zsh

local single_script_filter=""
local dry="0"

execute() {
    log "execute $@"
    [[ $dry != "1" ]] && "$@"
}

log() {
    [[ $dry != "1" ]] && echo "$@" || echo "[DRY RUN]: $@"
}

while [[ $# > 0 ]]; do
    [[ $1 == "--dry" ]] && dry="1" || single_script_filter="$1"
    shift
done

local script_dir=$(cd $(dirname "${ZSH_SOURCE[0]}") &> /dev/null && pwd)
log "run // script_dir: $script_dir -- args: $single_script_filter"
cd $script_dir
local scripts=(`find ./runs -maxdepth 1 -mindepth 1 -type f`)
for script in $scripts; do
    if [[ -x $script ]]; then
        if echo "$script" | grep -qv "$single_script_filter"; then
            log "filter is $single_script_filter // ignoring: $script"
            continue
        fi
        execute ./$script
    fi
done