Merge: doc: fixed some typos and other misc. corrections
[nit.git] / misc / jenkins / check_manpages.sh
1 #!/bin/bash
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Check that options are documented in the manpages of the tool.
17 # Usage: check_manpages from to
18
19 set -e
20
21 ret=0
22 for bin in bin/nit*; do
23
24 name=`basename $bin`
25
26 manc=share/man/nitc.md
27 man=share/man/$name.md
28
29 if ! test -f $man; then
30 echo "No manpage for binary $bin. Add one in $man"
31 echo ""
32 ret=1
33 continue
34 fi
35
36 $bin --help | grep '^ ' | sed 's/ */;/;s/ //' > check_manpages-option_list.out
37 while IFS=';' read opt cmt; do
38 # Generate first lines for the man page from --help
39 printf "%s\n" "$opt" | sed 's/, /`, `/g;s/^/### `/;s/$/`/' > check_manpages-from_help.out
40 echo "$cmt." >> check_manpages-from_help.out
41
42 # Generate grep pattern to search in the existing manpage
43 printf "%s\n" "$opt" | sed 's/, /`\\|`/g;s/^/###.*\\(`/;s/$/`\\)/' > check_manpages-grep_pattern.out
44
45 # Search pattern
46 if ! grep -A 1 -f check_manpages-grep_pattern.out $man > check_manpages-from_man.out; then
47 if ! grep -A 1 -f check_manpages-grep_pattern.out $manc > check_manpages-from_man.out; then
48 # Motif not found :(
49 echo "$opt: missing in the manpage $man. Here what is expected:"
50 echo ""
51 cat check_manpages-from_help.out
52 echo ""
53 ret=1
54 continue
55 fi
56
57 # found in `nitc.md`, check more only if dealing with nitc
58 [ "$man" = "$manc" ] || continue
59 fi
60
61 # Test what is expected
62 if ! diff -q <(sed -E 's/\s*(.*)//' check_manpages-from_help.out) <(sed -E 's/\s*(.*)//' check_manpages-from_man.out) > /dev/null; then
63 echo "$opt: mismatch documentation in the manpage $man. Here the word diff:"
64 echo ""
65 wdiff check_manpages-from_help.out check_manpages-from_man.out | colordiff
66 echo ""
67 ret=1
68 continue
69 fi
70 done < check_manpages-option_list.out
71 done
72
73 exit "$ret"