<commit_before>#!/usr/bin/env bash

koopa:::koopa_app() { # {{{1
    # """
    # Parse user input to 'koopa app'.
    # @note Updated 2021-03-01.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa app <ARG>...'."
    fi
    case "$name" in
        clean)
            name='delete-broken-app-symlinks'
            ;;
        list)
            name='list-app-versions'
            ;;
        link)
            name='link-app'
            ;;
        prune)
            name='prune-apps'
            ;;
        unlink)
            name='unlink-app'
            ;;
    esac
    shift 1
    koopa:::run_function "$name" "$@"
    return 0
}

koopa:::koopa_configure() { # {{{1
    # """
    # Parse user input to 'koopa configure'.
    # @note Updated 2021-04-29.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa configure <ARG>...'."
    fi
    shift 1
    koopa:::run_function "configure-${name}" "$@"
    return 0
}

koopa:::koopa_header() { # {{{1
    # """
    # Parse user input to 'koopa header'.
    # @note Updated 2021-01-19.
    #
    # Useful for private scripts using koopa code outside of package.
    # """
    local arg ext file koopa_prefix subdir
    koopa::assert_has_args_eq "$#" 1
    arg="$(koopa::lowercase "${1:?}")"
    koopa_prefix="$(koopa::prefix)"
    subdir='lang'
    case "$arg" in
        bash|posix|zsh)
            subdir="${subdir}/shell"
            ext='sh'
            ;;
        r)
            ext='R'
            ;;
        *)
            koopa::invalid_arg "$arg"
            ;;
    esac
    file="${koopa_prefix}/${subdir}/${arg}/include/header.${ext}"
    koopa::assert_is_file "$file"
    koopa::print "$file"
    return 0
}

koopa:::koopa_install() { # {{{1
    # """
    # Parse user input to 'koopa install'.
    # @note Updated 2021-05-07.
    # """
    local app app_args apps denylist pos
    app_args=()
    pos=()
    readarray -t denylist <<< "$(koopa:::koopa_install_denylist)"
    while (("$#"))
    do
        case "$1" in
            '')
                shift 1
                ;;
            --*|-*)
                app_args+=("$1")
                shift 1
                ;;
            *)
                pos+=("$1")
                shift 1
                ;;
        esac
    done
    [[ "${#pos[@]}" -gt 0 ]] && set -- "${pos[@]}"
    if [[ "$#" -eq 0 ]]
    then
        koopa::stop "Missing argument: 'koopa install <ARG>...'."
    fi
    apps=("$@")
    for app in "${apps[@]}"
    do
        if koopa::contains "$app" "${denylist[@]}"
        then
            koopa::stop "Invalid argument: '${app}'."
        fi
    done
    for app in "${apps[@]}"
    do
        # FIXME THIS IS ERRORING IN THE AMZN DOCKER IMAGE ARGH...
        # NEED TO FIGURE OUT HOW TO ADDRESS THIS...
        # FIXME Can we pass "${app_args[@]-}"  here instead?
        if koopa::is_array_non_empty "${app_args[@]:-}"
        then
            echo 'FIXME 1'
            koopa:::run_function "install-${app}" "${app_args[@]}"
        else
            echo 'FIXME2'
            koopa:::run_function "install-${app}"
        fi
    done
    return 0
}

koopa:::koopa_install_denylist() { # {{{1
    # """
    # App names that are intentionally not supported.
    # @note Updated 2021-05-07.
    # """
    local names
    names=(
        'app'
        'gnu-app'
        'start'
        'success'
    )
    koopa::print "${names[@]}"
}

koopa:::koopa_link() { # {{{1
    # """<commit_msg>Draft update<commit_after>#!/usr/bin/env bash

koopa:::koopa_app() { # {{{1
    # """
    # Parse user input to 'koopa app'.
    # @note Updated 2021-03-01.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa app <ARG>...'."
    fi
    case "$name" in
        clean)
            name='delete-broken-app-symlinks'
            ;;
        list)
            name='list-app-versions'
            ;;
        link)
            name='link-app'
            ;;
        prune)
            name='prune-apps'
            ;;
        unlink)
            name='unlink-app'
            ;;
    esac
    shift 1
    koopa:::run_function "$name" "$@"
    return 0
}

koopa:::koopa_configure() { # {{{1
    # """
    # Parse user input to 'koopa configure'.
    # @note Updated 2021-04-29.
    # """
    local name
    name="${1:-}"
    if [[ -z "$name" ]]
    then
        koopa::stop "Missing argument: 'koopa configure <ARG>...'."
    fi
    shift 1
    koopa:::run_function "configure-${name}" "$@"
    return 0
}

koopa:::koopa_header() { # {{{1
    # """
    # Parse user input to 'koopa header'.
    # @note Updated 2021-01-19.
    #
    # Useful for private scripts using koopa code outside of package.
    # """
    local arg ext file koopa_prefix subdir
    koopa::assert_has_args_eq "$#" 1
    arg="$(koopa::lowercase "${1:?}")"
    koopa_prefix="$(koopa::prefix)"
    subdir='lang'
    case "$arg" in
        bash|posix|zsh)
            subdir="${subdir}/shell"
            ext='sh'
            ;;
        r)
            ext='R'
            ;;
        *)
            koopa::invalid_arg "$arg"
            ;;
    esac
    file="${koopa_prefix}/${subdir}/${arg}/include/header.${ext}"
    koopa::assert_is_file "$file"
    koopa::print "$file"
    return 0
}

koopa:::koopa_install() { # {{{1
    # """
    # Parse user input to 'koopa install'.
    # @note Updated 2021-05-07.
    # """
    local app app_args apps denylist pos
    app_args=()
    pos=()
    readarray -t denylist <<< "$(koopa:::koopa_install_denylist)"
    while (("$#"))
    do
        case "$1" in
            '')
                shift 1
                ;;
            --*|-*)
                app_args+=("$1")
                shift 1
                ;;
            *)
                pos+=("$1")
                shift 1
                ;;
        esac
    done
    [[ "${#pos[@]}" -gt 0 ]] && set -- "${pos[@]}"
    if [[ "$#" -eq 0 ]]
    then
        koopa::stop "Missing argument: 'koopa install <ARG>...'."
    fi
    apps=("$@")
    for app in "${apps[@]}"
    do
        if koopa::contains "$app" "${denylist[@]}"
        then
            koopa::stop "Invalid argument: '${app}'."
        fi
    done
    for app in "${apps[@]}"
    do
        app="install-${app}"
        # FIXME THIS IS ERRORING IN THE AMZN DOCKER IMAGE ARGH...
        # NEED TO FIGURE OUT HOW TO ADDRESS THIS...
        # FIXME Can we pass "${app_args[@]-}"  here instead?
        if koopa::is_array_non_empty "${app_args[@]:-}"
        then
            echo 'FIXME 1'
            koopa:::run_function "$app" "${app_args[@]}"
        else
            echo 'FIXME2'
            koopa:::run_function "$app"
        fi
    done
    return 0
}

koopa:::koopa_install_denylist() { # {{{1
    # """
    # App names that are intentionally not supported.
    # @note Updated 2021-05-07.
    # """
    local names
    names=(
        'app'
        'gnu-app'
        'start'
        'success'
    )
    koopa::print "${names[@]}"
}

koopa:::koopa_link() { # {{{1
    # """
{'fraction_non_alphanumeric': 0.1737727910238429, 'fraction_numerical': 0.018513323983169707, 'mean_word_length': 1.5688040345821326, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '811439', 'n_tokens_mistral': 2588, 'n_tokens_neox': 2365, 'n_words': 546}