feat: add category help to pos dispatcher (pos <category> --help)

This commit is contained in:
Your Name
2026-08-05 04:09:19 -04:00
parent d591e71363
commit fe751bbc0c
5 changed files with 45 additions and 6 deletions
+1 -1
View File
@@ -458,7 +458,7 @@ Use conventional prefixes: `feat:`, `fix:`, `docs:`, `refactor:`, `chore:`
| `bin/flag-set` | 21 | Set a flag (optionally with a value) |
| `bin/flag-clear` | 21 | Unset a flag |
| `features/autostart.sh` | 14 | Boot-time feature (moved from `bin/`, flag-gated service) |
| `bin/pos` | 153 | CLI dispatcher with smart arg matching + logging |
| `bin/pos` | 191 | CLI dispatcher with smart arg matching + logging + category help |
| `bin/pos-docker-compose` | 363 | Largest script — full compose management |
| `bin/pos-system-firewall` | 284 | Interactive UFW manager |
| `bin/pos-system-backup` | 115 | Encrypted folder snapshots: path mode + `--service` (`/srv`, `~/srv` picker), tar + gpg AES-256 |
+2 -1
View File
@@ -49,7 +49,7 @@ pos docker compose up jellyfin
All non-interactive commands log to `~/.local/share/linux_post_install/logs/`.
`pos help <full command>` shows a tool's help, e.g. `pos help communication telegram` (all words joined with dashes → `pos-communication-telegram --help`).
`pos help <full command>` shows a tool's help, e.g. `pos help communication telegram` (all words joined with dashes → `pos-communication-telegram --help`). `pos <category>` or `pos <category> --help` shows a category's subcommands (derived from the `pos-<category>-*` filenames in `bin/` — no script execution, so it works even for root-only/interactive tools like `system-firewall`).
**When adding a command, `bin/pos` itself has two things to keep in sync:**
@@ -159,6 +159,7 @@ bash -n bin/your-tool
shellcheck bin/your-tool
./bin/your-tool --help
bin/pos help <full command> # confirm dispatch works
bin/pos <category> --help # confirm category listing includes the new tool (first tool in a new category)
```
---
+1 -1
View File
@@ -30,7 +30,7 @@ tries pos-docker-compose-up (not found)
tries pos-docker-compose (found) → runs with args "up jellyfin"
```
`pos help <full command>` runs that tool's `--help` (e.g. `pos help communication telegram`, `pos help docker compose` — the words are joined with dashes). Running `pos` with no args prints the built-in usage text (which doubles as the category cheat-sheet).
`pos help <full command>` runs that tool's `--help` (e.g. `pos help communication telegram`, `pos help docker compose` — the words are joined with dashes). `pos <category>` and `pos <category> --help` list that category's subcommands (derived from `bin/pos-<category>-*` filenames, no script execution). Running `pos` with no args prints the built-in usage text (which doubles as the category cheat-sheet).
---
+40 -2
View File
@@ -25,6 +25,36 @@ _pos_commands() {
echo "${cmds[*]}"
}
# ── Category helpers ────────────────────────────────────────────
_pos_category_exists() {
local cat="${1:-}" f
[ -n "$cat" ] || return 1
for f in "$self"/pos-"$cat"-*; do
[ -x "$f" ] && return 0
done
return 1
}
_pos_category_help() {
local cat="$1" sub subs=()
local f
for f in "$self"/pos-"$cat"-*; do
[ -x "$f" ] || continue
subs+=("${f##*/pos-$cat-}")
done
echo "pos $cat — $cat tools"
echo
echo "USAGE"
echo " pos $cat <command> [args]"
echo
echo "COMMANDS"
printf " %s\n" "${subs[@]}"
echo
echo "Run 'pos $cat <command> --help' for details on a command."
exit 0
}
# ── Help text ──────────────────────────────────────────────────
usage() {
cat <<'EOF'
@@ -73,8 +103,9 @@ EXAMPLES
pos docker vbox ls List Docker VMs
HELP
pos help <command> Show help for a command
pos --help Show this help
pos <category> --help Show a category's commands
pos help <command> Show help for a command
pos --help Show this help
LEGACY WRAPPERS
wr-ip, wr-checkport, wr-scan-ping, wr-docker,
@@ -108,6 +139,13 @@ fi
args=("$@")
n=${#args[@]}
# ── Category help: pos <category> [--help] ─────────────────────
if _pos_category_exists "${args[0]:-}"; then
if [ "$n" -eq 1 ] || { [ "$n" -eq 2 ] && { [ "${args[1]}" = "-h" ] || [ "${args[1]}" = "--help" ]; }; }; then
_pos_category_help "${args[0]}"
fi
fi
# ── Logging setup ──────────────────────────────────────────────
LOG_DIR="$HOME/.local/share/linux_post_install/logs"
mkdir -p "$LOG_DIR" 2>/dev/null || true
+1 -1
View File
@@ -45,7 +45,7 @@ _pos() {
_pos_complete_subcats() {
local cat="${words[1]}"
COMPREPLY=($(compgen -W "${cat_cmds[$cat]:-}" -- "$cur"))
COMPREPLY=($(compgen -W "${cat_cmds[$cat]:-} --help" -- "$cur"))
}
_pos_complete_compose_services() {