# 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 linuxps tree

___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|tree|\
        stime|stime_)
                            ___x_cmd_ps_"$op"    "$@"       ;;


        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
}

___x_cmd_ps_stime_(){
    ___x_cmd_ps_fingerprint_get_ "$1"
    ___x_cmd_ps_fingerprint_toepoch_ "$x_"
}

___x_cmd_ps_stime(){
    local op="$1";
    case "$op" in
        -h|--help)      ___x_cmd help -m ps stime;   return  ;;
    esac

    local x_
    ___x_cmd_ps_stime_ "$1" || return $?
    printf "%s\n" "$x_"
}

