utils/guard-lib/guardctl
Krzysztof kuhy Rudnicki 085d08b5c9 Split the two shell scripts and the gate's own config
aur-publish/publish.sh   439 -> 148 + lib/aur_registration 107
                                      + lib/aur_verify 122 + lib/aur_publish_one 107
  guard-lib/lib/file_guard.sh  350 -> 140 + file_guard_unlock 214
  file_length/config.py        252 -> 45 + _tables 202 + exemptions 77

The libs are sourced, never executed: they read the readonly config the entry
script declares, and a `readonly` re-run inside a twice-sourced lib aborts
under `set -e`. Verified by function parity rather than by eye — publish.sh
resolves the same 17 functions as before the split, guardctl the same 15 —
plus `shellcheck -x` clean on every file and a real `--help` / bad-option run.

file_length is the gate's own code, so a broken import there turns the gate
into a no-op. Split three ways to avoid an import cycle without a `# noqa`:
_tables holds the data, exemptions the rules that read it, config re-exports
both so `from file_length.config import is_generated` still resolves. The
first attempt was wrong — EXCLUDED_DIRS was left behind and every invocation
raised — caught because the gate was re-run in both modes rather than
assumed. Now verified: exit 0 on a clean file, exit 1 on an over-cap one,
--explain intact, and the same 61 exemption decisions as HEAD.

Also deletes baseline-2026-08-14.json and SURVEY-2026-08-14.txt: the task
forbids a baseline file, and nothing in the tree read either.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CFSGeWxHPY5rHUGrPqhcmG
2026-08-22 14:59:27 +02:00

62 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# guardctl - unified CLI for guard-lib's file-guard and package-block primitives.
set -euo pipefail
GUARD_LIB_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# When installed to /usr/local/bin, lib/ lives alongside it at
# /usr/local/lib/guard-lib; fall back to the repo layout for local runs.
if [[ -d "$GUARD_LIB_ROOT/lib" ]]; then
LIB_DIR="$GUARD_LIB_ROOT/lib"
elif [[ -d "/usr/local/lib/guard-lib" ]]; then
LIB_DIR="/usr/local/lib/guard-lib"
else
echo "guardctl: error: cannot locate lib/ directory" >&2
exit 1
fi
# shellcheck source=lib/common.sh
source "$LIB_DIR/common.sh"
# shellcheck source=lib/file_guard.sh
source "$LIB_DIR/file_guard.sh"
# shellcheck source=lib/file_guard_unlock.sh
source "$LIB_DIR/file_guard_unlock.sh"
# shellcheck source=lib/package_block.sh
source "$LIB_DIR/package_block.sh"
usage() {
cat <<'EOF'
Usage: guardctl <primitive> <subcommand> [args...]
Primitives:
file-guard install <name> --target <path> [--canonical <path>] [--bind-mount] [--plugin <script>] [--also-watch <path>]...
file-guard enforce <name>
file-guard unlock <name>
file-guard uninstall <name> [--keep-canonical]
file-guard status <name>
file-guard canonical-path <name>
file-guard bind-mount <name>
package-block start <name> --package <pkg> --lock-file <path> --days <N>
package-block check <name>
package-block status <name>
package-block end <name>
EOF
}
main() {
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
local primitive="$1"
shift
case "$primitive" in
file-guard) file_guard_main "$@" ;;
package-block) package_block_main "$@" ;;
-h|--help) usage ;;
*) usage; die "unknown primitive '$primitive'" ;;
esac
}
main "$@"