-
Notifications
You must be signed in to change notification settings - Fork 1
/
docgen.sh
executable file
·57 lines (40 loc) · 1.1 KB
/
docgen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# This extracts the header of the Dockerfile for each project
# and puts it into a README.md in each project's folder
# for documentation up front
#
# TODO: Handle more than one Dockerfile in a directory
VERSION="0.01"
YEAH_MODE=""
filter_comments() {
while read -r lines; do
echo "$lines" | sed -e 's/^#//g' | sed -e 's/^ //g'
done
}
write_to_readme() {
echo "Writing: $3"
cat > $3 <<-BERGUP
# ${1}
${2}
<sub>This README.md file was automatically generated by $(basename ${0}) v${VERSION}</sub>
BERGUP
}
for df in $PWD/*/*.dockerfile; do
let LN=0
while read -r f; do
if [[ $f =~ ^FROM[[:space:]] ]]; then
echo
echo "**** Dockerfile execution starts at line $LN ****"
echo "**** Here's the documentation ****"
echo
BODY="$(tail -n +2 $df | head -n $(($LN-1)) | filter_comments)"
HEADER="$(head -n1 $df | filter_comments)"
TARGET="$(dirname $df)/README.md"
echo "HEADER: $HEADER"
echo "BODY: $BODY"
echo "DIR: $TARGET"
write_to_readme "$HEADER" "$BODY" "$TARGET"
fi
LN=$((LN + 1))
done < "$df"
done