#! /usr/bin/zsh

setopt local_options nomatch
setopt +o nomatch

if [[ -n "$WRK_ENV" ]]
then
    nowrk
fi

prefix="$(wrk_config prefix)"
if [[ -d "$prefix/$1/" ]]
then

    export SRC="$prefix/$1"

    export OLD_LOC="$(pwd)";
    cd "$SRC";

    if [[ -f "$prefix/$1/devtools/wrk.ext" ]]
    then
        source "$SRC/devtools/wrk.ext";
    fi
    path_prepend "$SRC/devtools/bin";
    fpath_prepend "$SRC/devtools/functions"

    # TODO this was `*(,)` But I don't know why I made it like that
    # So I removed it once it breaks we can add it back and make a comment
    # here about why
    for file in *
    do
        autoload -Uz file
    done

    export WRK_ENV="$1"

else
    echo "$1 not found in $prefix";
    return 1
fi
