Skip to main content

Look for any file containing [[[cog when running recog; add a –check option

ID
901d092
date
2024-01-08 16:43:59+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
b2e1310
message
Look for any file containing [[[cog when running recog; add a --check option

Closes #9; closes #10
changed files
2 files, 20 additions, 5 deletions

Changed files

.github/workflows/test.yml (1225) → .github/workflows/test.yml (1190)

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 1760d83..3171640 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -37,8 +37,7 @@ jobs:
         flake8 --ignore=E501,W503
 
     - name: Check README files with Cog
-      run: |
-        find . -name README.md | xargs cog -c --check
+      run: ./text/recog --check
 
     - name: Run tests
       run: |

text/recog (335) → text/recog (618)

diff --git a/text/recog b/text/recog
index 55cde7f..e46cdc9 100755
--- a/text/recog
+++ b/text/recog
@@ -1,7 +1,8 @@
 #!/usr/bin/env bash
-# Run Cog to generate the README files in this repo.
+# Regenerate any files that use Cog.
 #
-# This creates the per-README list of the individual scripts and files.
+# Among other things, this is used to create the per-README list of
+# the individual scripts and files in this repo.
 #
 # Here Cog is Ned Batchelder's file generation tool, described here:
 # https://nedbatchelder.com/code/cog
@@ -9,4 +10,19 @@
 set -o errexit
 set -o nounset
 
-find . -name README.md | sort | xargs cog -c -r
+if [[ "$@" =~ "--check" ]]; then
+  action="check_only"
+else
+  action="apply_changes"
+fi
+
+files=$(
+  find . -type f -not -path "./.venv/*" -exec grep -rl "\[\[\[cog" {} + | sort)
+
+for f in $files; do
+  if [[ "$action" == "check_only" ]]; then
+    cog -c --check "$f"
+  else
+    cog -c -r "$f"
+  fi
+done