Files
a.gritsenkoandClaude Opus 5.5 11283c573a Add bash completion for pkica
Static completion rules for all pkica commands, options and option values,
plus unit, interactive (tmux) and --help reconciliation tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 23:22:43 +03:00

56 lines
1.9 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Сверка таблиц pkica.bash-completion с реальным выводом `pkica ... --help`.
# Запуск (из WSL/Linux): bash tests/check_tree.sh [путь к pkica]
# Без аргумента используется pkica из PATH.
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
pkica=${1:-$(command -v pkica)}
[[ -x $pkica ]] || { echo "pkica not found: укажите путь аргументом"; exit 1; }
# shellcheck disable=SC1091
source "$root/pkica.bash-completion" || exit 1
fail=0 nodes=0
walk()
{
local path=$1 help cmds opts expected_cmds expected_opts sub
help=$("$pkica" ${path#pkica} --help 2>&1)
nodes=$((nodes + 1))
cmds=$(awk '/^Commands:/{f=1;next} f&&/^$/{f=0} f&&/^ [a-z]/{print $1}' <<<"$help" |
tr '\n' ' ' | sed 's/ $//')
opts=$(awk '/^Options:/{f=1;next} /^(Commands:)?$/{f=0}
f&&/^ -/{s=$1; gsub(/-\?\|/,"",s); if($2 ~ /^</) s=s "="; printf "%s ", s}' <<<"$help" |
sed 's/ $//')
expected_cmds=${_pkica_cmds[$path]-}
expected_opts=${_pkica_opts[$path]:--h|--help}
if [[ $cmds != "$expected_cmds" ]]; then
fail=$((fail + 1))
printf 'MISMATCH commands [%s]\n help: %s\n completion: %s\n' "$path" "$cmds" "$expected_cmds"
fi
if [[ $opts != "$expected_opts" ]]; then
fail=$((fail + 1))
printf 'MISMATCH options [%s]\n help: %s\n completion: %s\n' "$path" "$opts" "$expected_opts"
fi
for sub in $cmds; do
walk "$path $sub"
done
}
walk pkica
# Узлы в таблицах, которых нет в утилите.
for key in "${!_pkica_cmds[@]}" "${!_pkica_opts[@]}"; do
"$pkica" ${key#pkica} --help 2>&1 | grep -q "^Usage: $key " || {
fail=$((fail + 1))
printf 'UNKNOWN node in completion: [%s]\n' "$key"
}
done
echo "checked nodes: $nodes, mismatches: $fail"
((fail == 0))