Skip to content

Commit bbc1868

Browse files
committed
Add --check-only option to toc checking
1 parent c17dd65 commit bbc1868

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

docs/build_toc.sh

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
#!/usr/bin/env bash
2-
32
set -e
43

54
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
65
project_root="$(dirname "$script_dir")"
6+
check_only=0
77

88
show_help() {
99
me=$(basename "$0")
1010
cat <<EOF
1111
$me: Build table of contents for documentation directories
1212
13-
Usage: $me [--help] [--source <path>]
13+
Usage: $me [--help] [--source <path>] [--check-only]
1414
1515
Options:
16-
--help Show this help message
17-
--source Path to project root directory (defaults to parent of the script directory)
16+
--help Show this help message
17+
--source Path to project root directory (defaults to parent of the script directory)
18+
--check-only Check if TOC needs updating, exit 1 if changes needed
1819
EOF
1920
}
2021

@@ -28,9 +29,12 @@ while [[ "$#" -gt 0 ]]; do
2829
project_root="$2"
2930
shift
3031
;;
32+
--check-only)
33+
check_only=1
34+
;;
3135
*)
32-
echo "unrecognized argument: $1"
33-
show_help
36+
echo "unrecognized argument: $1" >&2
37+
show_help >&2
3438
exit 1
3539
;;
3640
esac
@@ -91,17 +95,33 @@ namespace toc
9195
EOL
9296

9397
if ! mcs -r:System.Core "$temp_dir/temp_program.cs" -out:"$temp_dir/toc-builder.exe"; then
94-
echo "Compilation failed"
98+
echo "Compilation of $script_dir/scripts/Program.cs failed" >&2
9599
exit 1
96100
fi
97101

98102
for dir in "user-guide" "gfx-user-guide"; do
99103
if [ -d "$script_dir/$dir" ]; then
104+
if [ "$check_only" -eq 1 ]; then
105+
# Ensure working directory is clean
106+
if ! git diff --quiet "$script_dir/$dir/toc.html" 2>/dev/null; then
107+
echo "Working directory not clean, cannot check TOC" >&2
108+
exit 1
109+
fi
110+
fi
111+
100112
if ! mono "$temp_dir/toc-builder.exe" "$script_dir/$dir"; then
101-
echo "TOC generation failed for $dir"
113+
echo "TOC generation failed for $dir" >&2
102114
exit 1
103115
fi
116+
117+
if [ "$check_only" -eq 1 ]; then
118+
if ! git diff --quiet "$script_dir/$dir/toc.html" 2>/dev/null; then
119+
git diff --color "$script_dir/$dir/toc.html"
120+
git checkout -- "$script_dir/$dir/toc.html" 2>/dev/null
121+
exit 1
122+
fi
123+
fi
104124
else
105-
echo "Directory $dir not found"
125+
echo "Directory $dir not found" >&2
106126
fi
107127
done

0 commit comments

Comments
 (0)