# shellcheck shell=dash

___x_cmd log init icmd
xrc:mod:lib     icmd   alias

# alias i='___x_cmd icmd'
___x_cmd_icmd___main(){
    [ $# -gt 0 ]    ||      set -- --help

    local op="$1"; shift
    case "$op" in
        -h|--help)  ___x_cmd help -m icmd               "$@" ;;
        --alias)    ___x_cmd_icmd_alias                 "$@" ;;

        --login|--logout|--cat|--put|--eput|--get|--ls)
                    ___x_cmd hub         "${op#--}"     "$@" ;;

        -l|--ll)    ___x_cmd_icmd___ll                  "$@" ;;
        --update)   ___x_cmd_icmd___update              "$@" ;;
        --which|--which_)
                    ___x_cmd_icmd___"${op#--}"          "$@" ;;

        *)          ___x_cmd_icmd___run  "$op"          "$@" ;;
    esac
}

___x_cmd_icmd___ll(){
    ___x_cmd hub ll "$@"
}

___x_cmd_icmd___run(){
    local res="$1"; shift

    local x_
    ___x_cmd_icmd___which_ "$res" || return $?
    ___x_cmd runfile "$x_" "$@"
}

___x_cmd_icmd___which_(){
    local res="$1"; shift

    local local_binfp="$HOME/.i-cmd/$res"
    x_="$local_binfp/${res#/}"
    [ ! -f "$x_" ] || return 0

    ___x_cmd hub file which_ "$res"
}

___x_cmd_icmd___which(){
    local x_=""
    ___x_cmd_icmd___which_ "$@" || return $?
    printf "%s\n" "${x_}"
}


___x_cmd_icmd___update(){
    ___x_cmd hub file update "$@"
}
