feat: nested pos subcommands — POS_SUBCMDS header, nested category help + completion
This commit is contained in:
@@ -26,6 +26,8 @@ _pos_commands() {
|
||||
}
|
||||
|
||||
# ── Category list (sorted, filename-derived) ─────────────────────
|
||||
# Nested sub-tools (pos-<cat>-<a>-<b> where pos-<cat>-<a> exists) are
|
||||
# omitted from the cheat-sheet line — they are shown under their parent tool.
|
||||
_pos_category_list() {
|
||||
local -A cats=()
|
||||
local cmd cat f
|
||||
@@ -36,10 +38,19 @@ _pos_category_list() {
|
||||
[ "$cat" = "$cmd" ] && continue
|
||||
cats["$cat"]+="${cmd#*-} "
|
||||
done
|
||||
local c line subs joined
|
||||
local c subs joined s s2 top=() is_nested
|
||||
for c in $(printf '%s\n' "${!cats[@]}" | sort); do
|
||||
subs=(${cats[$c]})
|
||||
joined="$(IFS='|'; echo "${subs[*]}")"
|
||||
top=()
|
||||
for s in "${subs[@]}"; do
|
||||
is_nested=0
|
||||
for s2 in "${subs[@]}"; do
|
||||
[ "$s2" = "$s" ] && continue
|
||||
if [[ "$s" == "$s2-"* ]]; then is_nested=1; break; fi
|
||||
done
|
||||
[ "$is_nested" -eq 1 ] || top+=("$s")
|
||||
done
|
||||
joined="$(IFS='|'; echo "${top[*]}")"
|
||||
printf " %-14s%s\n" "$c" "$joined"
|
||||
done
|
||||
}
|
||||
@@ -55,11 +66,36 @@ _pos_category_exists() {
|
||||
}
|
||||
|
||||
_pos_category_help() {
|
||||
local cat="$1" sub subs=()
|
||||
local f
|
||||
local cat="$1" f
|
||||
local files=() s d
|
||||
for f in "$self"/pos-"$cat"-*; do
|
||||
[ -x "$f" ] || continue
|
||||
subs+=("${f##*/pos-$cat-}")
|
||||
files+=("${f##*/pos-$cat-}")
|
||||
done
|
||||
mapfile -t files < <(printf '%s\n' "${files[@]}" | sort -u)
|
||||
|
||||
local -A desc subcmds
|
||||
local sc
|
||||
for s in "${files[@]}"; do
|
||||
d="$(sed -n '/^# POS: /{s/^# POS: //;p;q}' "$self/pos-$cat-$s" 2>/dev/null)"
|
||||
[ -n "$d" ] && desc["$s"]="${d#*— }"
|
||||
sc="$(sed -n '/^# POS_SUBCMDS: /{s/^# POS_SUBCMDS: //;p;q}' "$self/pos-$cat-$s" 2>/dev/null)"
|
||||
[ -n "$sc" ] && subcmds["$s"]="$sc"
|
||||
done
|
||||
|
||||
# Nested sub-tools: pos-<cat>-<a>-<b> lists "b" under <a>.
|
||||
local s2 extra
|
||||
for s in "${files[@]}"; do
|
||||
for s2 in "${files[@]}"; do
|
||||
[ "$s2" = "$s" ] && continue
|
||||
if [[ "$s2" == "$s-"* ]]; then
|
||||
extra="${s2#$s-}"
|
||||
case " ${subcmds[$s]:-} " in
|
||||
*" $extra "*) ;;
|
||||
*) subcmds["$s"]="${subcmds[$s]:-}${subcmds[$s]:+ }$extra" ;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo "pos $cat — $cat tools"
|
||||
@@ -68,7 +104,19 @@ _pos_category_help() {
|
||||
echo " pos $cat <command> [args]"
|
||||
echo
|
||||
echo "COMMANDS"
|
||||
printf " %s\n" "${subs[@]}"
|
||||
local is_nested c
|
||||
for s in "${files[@]}"; do
|
||||
is_nested=0
|
||||
for s2 in "${files[@]}"; do
|
||||
[ "$s2" = "$s" ] && continue
|
||||
if [[ "$s" == "$s2-"* ]]; then is_nested=1; break; fi
|
||||
done
|
||||
[ "$is_nested" -eq 1 ] && continue
|
||||
printf ' %-28s%s\n' "$s" "${desc[$s]:-}"
|
||||
for c in ${subcmds[$s]:-}; do
|
||||
printf ' %s %s\n' "$s" "$c"
|
||||
done
|
||||
done
|
||||
echo
|
||||
echo "Run 'pos $cat <command> --help' for details on a command."
|
||||
exit 0
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
set -euo pipefail
|
||||
# POS: communication telegram — Send Telegram messages/files/links/stickers via Bot API (send, test, config set)
|
||||
# POS_FLAGS: --send --type --caption --parse-mode --no-preview --token --chat-id
|
||||
# POS_SUBCMDS: send test config
|
||||
|
||||
CONFIG_DIR="$HOME/.config/linux_post_install"
|
||||
CONFIG_FILE="$CONFIG_DIR/telegram.env"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
# POS: docker compose — Docker Compose service manager (ls/up/down/restart/logs/update/config)
|
||||
# POS_SUBCMDS: ls installed up down restart logs update config
|
||||
source "$(dirname "$0")/../lib/common.sh" 2>/dev/null || source "$(dirname "$0")/common.sh"
|
||||
|
||||
SCALE_DIR="/usr/local/share/linux_post_install/scale-tail/services"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
# POS: docker vbox — Disposable Docker-based VMs (create/enter/start/stop/rm/ls)
|
||||
# POS_SUBCMDS: create enter stop start rm ls
|
||||
source "$(dirname "$0")/../lib/common.sh" 2>/dev/null || source "$(dirname "$0")/common.sh"
|
||||
|
||||
usage() {
|
||||
|
||||
Reference in New Issue
Block a user