From 6378311ac5865bef0e8b78af45a59c9acedf08a0 Mon Sep 17 00:00:00 2001 From: sneak Date: Wed, 18 Nov 2026 21:31:09 +0000 Subject: [PATCH] script/update-policy: put the code in a main function The script ran its code at the top level. prompts/CODE_STYLEGUIDE.md says to put all shell code in functions, with a main called at the bottom, and every other script in script/ does. The code now sits in main(), and the last line calls it. Model: opus-5-5 --- script/update-policy | 72 +++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/script/update-policy b/script/update-policy index b0950f9..fc78ab2 100755 --- a/script/update-policy +++ b/script/update-policy @@ -19,41 +19,45 @@ die() { exit 1 } -cd "$ROOT" -[ ! -e prompts/REPO_POLICIES.md ] || - die "this is the prompts repo, where these files come from" -[ ! -e REPO_POLICIES.md ] || - die "REPO_POLICIES.md is at the root;" \ - "move it into docs/ with git mv and fix the links to it first" +main() { + cd "$ROOT" + [ ! -e prompts/REPO_POLICIES.md ] || + die "this is the prompts repo, where these files come from" + [ ! -e REPO_POLICIES.md ] || + die "REPO_POLICIES.md is at the root;" \ + "move it into docs/ with git mv and fix the links to it first" -paths="" -for entry in $FILES; do - paths="$paths ${entry#*:}" -done -[ -z "$(git status --porcelain -- $paths)" ] || - die "commit or discard your changes to these files first:$paths" + paths="" + for entry in $FILES; do + paths="$paths ${entry#*:}" + done + [ -z "$(git status --porcelain -- $paths)" ] || + die "commit or discard your changes to these files first:$paths" -# Every file is fetched before any is replaced. The temporary directory -# is inside the repo so that mv renames: the running script is replaced -# by a new file, never rewritten in place. -tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")" -trap 'rm -rf "$tmp"' EXIT -for entry in $FILES; do - mkdir -p "$tmp/$(dirname "${entry#*:}")" - wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" || - die "cannot fetch $RAW_URL/${entry%%:*}" -done -chmod 755 "$tmp/script/update-policy" + # Every file is fetched before any is replaced. The temporary + # directory is inside the repo so that mv renames: the running script + # is replaced by a new file, never rewritten in place. + tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")" + trap 'rm -rf "$tmp"' EXIT + for entry in $FILES; do + mkdir -p "$tmp/$(dirname "${entry#*:}")" + wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" || + die "cannot fetch $RAW_URL/${entry%%:*}" + done + chmod 755 "$tmp/script/update-policy" -for path in $paths; do - mkdir -p "$(dirname "$path")" - mv "$tmp/$path" "$path" -done + for path in $paths; do + mkdir -p "$(dirname "$path")" + mv "$tmp/$path" "$path" + done -git add -- $paths -if git diff --cached --quiet -- $paths; then - echo "update-policy: already current, nothing to commit" -else - git commit -q -m "Update policy files from prompts" -- $paths - echo "update-policy: committed; review it, then push" -fi + git add -- $paths + if git diff --cached --quiet -- $paths; then + echo "update-policy: already current, nothing to commit" + else + git commit -q -m "Update policy files from prompts" -- $paths + echo "update-policy: committed; review it, then push" + fi +} + +main "$@"