# shellcheck shell=dash     # { Author: Li Junhao, License: AGPLv3 }

alias shgen:from:x_=___x_cmd_shgen_fromx_

___x_cmd_shgen(){
    [ $# -gt 0 ] || {
        x:error "No subcmd name provided"
        return 1
    }

    local op="$1"; shift
    case "$op" in
        fromx_)
            ___x_cmd_shgen_fromx_ "$@"
            ;;
    esac
}

___x_cmd_shgen_fromx_(){
    while [ $# -gt 0 ]; do
        case "$1" in
            --helpcmd)
                [ $# -gt 2 ] || {
                    x:error "Option --helpcmd require 1 argument"
                    return 1
                }
                # TODO: Should be shqu1
                ___X_CMD_HELP_CMD="'$2'"; shift 2
                ;;
            *)  break
        esac
    done

    [ -n "$1" ] || {
        x:error "Require 1 argument as function name"
        return 1
    }

    eval "${1}"'(){
        local ___X_CMD_HELP_CMD='"$___X_CMD_HELP_CMD"'; shift
        local x_
        '"${1}_"' "$@" || return $?
        printf "%s\n" "$x_"
    }'
}

___x_cmd_proxyrun(){
    local ___X_CMD_HELP_CMD="$1"; shift
    "$@"
}

___x_cmd_proxyrun_(){
    local ___X_CMD_HELP_CMD="$1"; shift
    local x_
    "$@" || return $?
    printf "%s\n" "$x_"
}

