# shellcheck shell=dash disable=SC3043,SC2120 # xrc

___x_cmd log init boot

___X_CMD_BOOT_DATA="$___X_CMD_ROOT_DATA/boot"

xrc:mod:lib boot    \
    mod rc chrun ch alterdefault \
    initrootbin initrcfile initrcfile1 ensurerccode

___x_cmd_boot___main(){
    if [ ! -d "$___X_CMD_BOOT_DATA" ] && ! ___x_cmd mkdirp "$___X_CMD_BOOT_DATA"; then
        printf "boot abort for mkdir fails: %s\n" "$___X_CMD_BOOT_DATA" >&2
        return 1
    fi

    [ $# -gt 0 ]    ||  set -- --help

    local op="$1";      shift
    case "$op" in
        -h|--help)      ___x_cmd help -m boot ;;

        alterdefault)   ___x_cmd_boot_alterdefault   "$@" ;;

        init)           ___x_cmd_boot___init         "$@" ;;
        clear)          ___x_cmd_boot___clear        "$@" ;;

        initrcfile|initrcfile1|ensurerccode|ensurerccodewithoutextra|initrootbin)
                        "___x_cmd_boot_$op"          "$@" ;;

        ch)             ___x_cmd_boot_ch             "$@" ;;
        chrun)          ___x_cmd_boot_chrun          "$@" ;;
        # setup)          xrc:mod boot/lib/setup ;; # alread move to history
        rc)             ___x_cmd_boot_rc             "$@" ;;

        mod)            ___x_cmd_boot_mod            "$@" ;;

        *)              N=boot M="Unsupported subcmd -> $op" log:ret:64 ;;
    esac
}

___x_cmd_boot___init(){
    case "$1" in
        -h|--help)  ___x_cmd help -m boot init  ;    return ;;
    esac
    xrc:mod boot/lib/init
}

___x_cmd_boot___clear(){
    case "$1" in
        -h|--help)  ___x_cmd help -m boot clear ;    return ;;
    esac
    xrc:mod boot/lib/clear
}
