#!/bin/bash

set -e

PREGEN_DIR="@PREGEN_DIR@"

exit_unknown() {
    echo "lua-wrapper: ERROR: Unknown command: $@" >&2
    exit 1
}

case "$1" in
    */docs/05-awesomerc.md.lua )
        a="/docs/05-awesomerc.md"
        [[ "$2" =~ "$a" ]] || exit_unknown "$@"
        cp "$PREGEN_DIR$a" "$2"
        b="/awesomerc.lua"
        [[ "$4" =~ "$b" ]] || exit_unknown "$@"
        cp "$PREGEN_DIR$b" "$4"
        c="/script_files/rc.lua"
        [[ "$5" =~ "$c" ]] || exit_unknown "$@"
        cp "$PREGEN_DIR$c" "$5"
        ;;
    */docs/06-appearance.md.lua )
        a="/docs/06-appearance.md"
        [[ "$2" =~ "$a" ]] || exit_unknown "$@"
        cp "$PREGEN_DIR$a" "$2"
        ;;
    */docs/build_rules_index.lua )
        cp "$PREGEN_DIR/docs/common/$(basename "$2")" "$2"
        ;;
    */docs/sample_theme.lua )
        cp "$PREGEN_DIR/script_files/theme.lua" "$2"
        ;;
    * )
        exit_unknown "$@"
esac
