# shellcheck shell=dash

# If USING LINUX/BSD -- have procfs

# If USING MACOS
___x_cmd log init ps
xrc:mod:lib     ps      ai  exec fingerprint child fz

___x_cmd_ps___main(){
    [ $# -gt 0 ]    ||  set -- --exec

    local op="$1";  shift
    case "$op" in
        -h|--help)          ___x_cmd help -m ps ;   return  ;;
        --tocsv)            ___x_cmd_ps___tocsv  "$@"       ;;
        --tojson)           ___x_cmd_ps___tojson "$@"       ;;


        --exec)             ___x_cmd_ps___exec   "$@"       ;;

        --ai|=)             ___x_cmd_ps___ai     "$@"       ;;
        fingerprint)        ___x_cmd_ps_fingerprint "$@"    ;;

        fz|--fz)            ___x_cmd_ps_fz       "$@"       ;;

        --child)            ___x_cmd_ps___child "$@"        ;;

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


___x_cmd_ps___tocsv(){
    local ncol="${1:-auto}"
    ___x_cmd csv convert --col -n "$ncol" \
      | ___x_cmd csv header --mod "%CPU=CPU" "%MEM=MEM"
}

___x_cmd_ps___tojson(){
    ___x_cmd_ps___tocsv | ___x_cmd csv tojson
}

