sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

test-builtin-mandb-cache.sh (3139B)


      1 #!/usr/bin/env bash
      2 
      3 # https://github.com/akinomyoga/ble.sh/issues/325#issuecomment-1546542201
      4 
      5 # shellcheck disable=1090
      6 blesh=~/.mwg/src/ble.sh/out/ble.sh
      7 if [[ ! -s $blesh ]]; then
      8   blesh=~/.local/share/blesh/ble.sh
      9   if [[ ! -s $blesh ]]; then
     10     echo "$0: failed to find ble.sh." >&2
     11     return 1
     12   fi
     13 fi
     14 
     15 source "$blesh" --lib
     16 ble-import core-complete
     17 ble-import core-cmdspec
     18 
     19 # Note: +f was removed from declare, typeset, local.
     20 # Note: -DEI was removed from compgen
     21 declare -A command_options=([":"]="" [source]="" [alias]="-p" [bg]=""
     22   [bind]="-m -l -p -s -v -P -S -V -X -q -u -r -f -x" [break]="" [builtin]=""
     23   [caller]="" [cd]="-L -P -e -@" [command]="-p -V -v" [compgen]="-a -b -c -d -e
     24   -f -g -j -k -s -u -v -o -A -G -W -F -C -X -P -S" [complete]="-a -b -c -d -e
     25   -f -g -j -k -s -u -v -o -D -E -I -A -G -W -F -C -X -P -S -p -r" [compopt]="-o
     26   -D -E -I +o" [continue]="" [declare]="-a -A -f -F -g -i -I -l -n -r -t -u -x
     27   -p +a +A +i +l +n +r +t +u +x" [typeset]="-a -A -f -F -g -i -I -l -n -r -t -u
     28   -x -p +a +A +i +l +n +r +t +u +x" [dirs]="-c -l -p -v" [disown]="-a -r -h"
     29   [echo]="-n -e -E" [enable]="-a -d -n -p -s -f" [eval]="" [exec]="-c -l -a"
     30   [exit]="" [export]="-f -n -p" [fc]="-e -l -n -r -s" [fg]="" [getopts]=""
     31   [hash]="-l -r -p -d -t" [help]="-d -m -s" [history]="-c -d -a -n -r -w -p -s"
     32   [jobs]="-l -n -p -r -s -x" [kill]="-s -n -l -L" [local]="-a -A -f -F -g -i -I
     33   -l -n -r -t -u -x -p +a +A +i +l +n +r +t +u +x" [logout]="" [mapfile]="-d -n
     34   -O -s -t -u -C -c" [readarray]="-d -n -O -s -t -u -C -c" [popd]="-n"
     35   [printf]="-v" [pushd]="-n" [pwd]="-L -P" [read]="-e -r -s -a -d -i -n -N -p
     36   -t -u" [readonly]="-a -A -f -p" [return]="" [set]="-a -b -e -f -h -k -m -n -p
     37   -t -u -v -x -B -C -E -H -P -T -o +a +b +e +f +h +k +m +n +p +t +u +v +x +B +C
     38   +E +H +P +T +o" [shift]="" [shopt]="-p -q -s -u -o" [suspend]="-f" [test]="-a
     39   -b -c -d -e -f -g -h -k -p -r -s -t -u -w -x -G -L -N -O -S -ef -nt -ot -o -v
     40   -R -z -n -eq -ne -gt -lt -ge -le" [times]="" [trap]="-l -p" [type]="-a -f -t
     41   -p -P" [ulimit]="-H -S -a -b -c -d -e -f -i -k -l -m -n -p -q -r -s -t -u -v
     42   -x -P -R -T" [umask]="-p -S" [unalias]="-a" [unset]="-f -v -n" [wait]="-f -n
     43   -p")
     44 
     45 declare -i counter=0
     46 set -f
     47 
     48 for name in "${!command_options[@]}"; do
     49   suggestions=()
     50   # shellcheck disable=SC2154
     51   ble/complete/mandb/generate-cache "$name" &&
     52     ble/string#split-words suggestions "$(awk --field-separator=$'\x1c' '{print $1}' "$ret")"
     53 
     54   options=()
     55   ble/string#split-words options "${command_options[$name]}"
     56 
     57   echo "$name:"
     58   #echo "$name: ${suggestions[*]}"
     59   declare -i is_broken=0
     60   for option in "${options[@]}"; do
     61     grep --quiet -- "$option" <<< "${suggestions[*]}" || {
     62       echo "- '$option' is not suggested, while it's documented"
     63       is_broken=1
     64     }
     65   done
     66 
     67   for option in "${suggestions[@]}"; do
     68     [[ $option == --help || $option == -- ]] && continue
     69     grep --quiet -- "$option" <<< "${options[*]}" || {
     70       echo "- '$option' is suggested, while it's unknown"
     71       is_broken=1
     72     }
     73   done
     74 
     75   counter+=$is_broken
     76   echo
     77 done
     78 
     79 echo "$counter out of ${#command_options[@]} are broken"