asciidoctor_syntax_check.bash 668 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

if ! [ -x "$(command -v asciidoctor)" ]; then
    echo "Error: asciidoctor is not installed"
    exit 1
fi

if [ -z "$1" ] ; then
    echo "Error: No argument supplied - path needed"
    exit 1
fi

touch output.log # avoid failing if no adoc files exist
while IFS= read -r -d '' filename; do
  asciidoctor "$filename" 2>&1 | tee -a output.log
done < <(find "$1" -name '*.adoc' -type f -print0)
adoc_errors=0 ; adoc_warnings=0
adoc_errors=$(grep -c "ERROR" output.log)
adoc_warnings=$(grep -c "WARNING" output.log)
echo "AsciiDoc format Found ${adoc_errors} errors and ${adoc_warnings} warnings"
if [ "${adoc_errors}" -eq 0 ]; then exit 0; else exit 1; fi