1
1
#! /usr/bin/env bash
2
-
3
2
set -e
4
3
5
4
script_dir=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
6
5
project_root=" $( dirname " $script_dir " ) "
6
+ check_only=0
7
7
8
8
show_help () {
9
9
me=$( basename " $0 " )
10
10
cat << EOF
11
11
$me : Build table of contents for documentation directories
12
12
13
- Usage: $me [--help] [--source <path>]
13
+ Usage: $me [--help] [--source <path>] [--check-only]
14
14
15
15
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
18
19
EOF
19
20
}
20
21
@@ -28,9 +29,12 @@ while [[ "$#" -gt 0 ]]; do
28
29
project_root=" $2 "
29
30
shift
30
31
;;
32
+ --check-only)
33
+ check_only=1
34
+ ;;
31
35
* )
32
- echo " unrecognized argument: $1 "
33
- show_help
36
+ echo " unrecognized argument: $1 " >&2
37
+ show_help >&2
34
38
exit 1
35
39
;;
36
40
esac
@@ -91,17 +95,33 @@ namespace toc
91
95
EOL
92
96
93
97
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
95
99
exit 1
96
100
fi
97
101
98
102
for dir in " user-guide" " gfx-user-guide" ; do
99
103
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
+
100
112
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
102
114
exit 1
103
115
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
104
124
else
105
- echo " Directory $dir not found"
125
+ echo " Directory $dir not found" >&2
106
126
fi
107
127
done
0 commit comments