# shellcheck shell=dash

x log init cwe
xrc:mod:lib     cwe                         \
    info/_index                           \
    info/lookup                           \
    info/render                           \
    la/_index                             \
    la/stream                             \
    la/fmt                                \
    fz/_index                             \
    data/_index                           \
    data/fetch                            \
    util

___x_cmd_cwe___main(){
    # No args → behave like `x cwe ls`. Help is still available via -h / --help.
    [ "$#" -gt 0 ] || set -- ls

    local op="$1"; shift
    case "$op" in
        -h|--help)          ___x_cmd help -m cwe           "$@" ; return 0 ;;

        # Lookup + browsing
        info)               ___x_cmd_cwe_info             "$@" ;;
        ls)                 ___x_cmd_cwe_la               "$@" ;;
        fz)                 ___x_cmd_cwe_fz                "$@" ;;

        # Local cache management
        update)             ___x_cmd_cwe_data_update      "$@" ;;
        data)               ___x_cmd_cwe_data             "$@" ;;

        # Default fallbacks: bare-arg dispatch.
        #   `x cwe CWE-79` → `x cwe info CWE-79`
        #   `x cwe 79`     → `x cwe info CWE-79`
        CWE-*|[0-9]*)
            ___x_cmd_cwe_info "$op" "$@"
            ;;
        *)
            cwe:warn "unknown subcommand: $op (try 'x cwe --help')"
            return 64
            ;;
    esac
}