-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathhieradocs.sh
executable file
·62 lines (53 loc) · 1.87 KB
/
hieradocs.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
58
59
60
61
62
#!/bin/sh
# hiera::key::name:
# datatype: String.
# description: |
# String describing the key.
# found_in:
# - someFile.yaml
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
PATTERN_PARAM=\[[*]\([^*]*\)[*]\]
PATTERN_COMMENT=\(.+\)
HIERA_DIR=../hieradata
for file in `git grep -l class manifests/ | sort`;
do
CLASS=`grep class $file | awk '{print $2}'`
PARAM=""
DOCS=""
# look only at comments that begin a line. strip off the leading # and spaces for simplification
for line in `cat $file | grep ^# | sed 's/^#[ ]*//g'` ;
do
if [[ $line =~ $PATTERN_PARAM ]] ;
then
if [ "$PARAM" != "" ] ;
then
# remove leading white space and double periods (anywhere)
DOCS=`echo $DOCS | sed 's/^[\t .]*//g' | sed 's/\.\././g'`
echo "${PARAM}-A# ${PARAM}:"
echo "${PARAM}-B# datatype: String."
if [ "$DOCS" != "" ];
then
echo "${PARAM}-C# description: |"
echo "${PARAM}-D# ${DOCS}"
fi
if [[ `grep -Rl $PARAM $HIERA_DIR | egrep -v -e \.git -e README.md -e definitions.yaml | wc -l` > 0 ]];
then
echo "${PARAM}-E# found_in:"
for found in `grep -Rl $PARAM $HIERA_DIR | egrep -v -e \.git -e README.md -e definitions.yaml | sed "s#$HIERA_DIR\/##g"`;
do
echo "${PARAM}-F# - ${found}"
done
fi
fi
# this is a param definition, get the name and reset docs
PARAM="${CLASS}::${BASH_REMATCH[1]}"
DOCS=
elif [[ $line =~ $PATTERN_COMMENT ]] ;
then
# this is documentation, capture it
DOCS="${DOCS}. ${BASH_REMATCH[1]}"
fi
done
done
IFS=$SAVEIFS