Created
December 11, 2018 12:41
-
-
Save henriquemoody/2496ab71c044e276c48622c9e7216304 to your computer and use it in GitHub Desktop.
Updates "See also" section for the Respect\Validation rules.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare -A REFERENCES | |
while read filename; do | |
declare rule=$(cut -d '/' -f 2 <<< "${filename}" | cut -d '.' -f 1) | |
declare related_rules=$( | |
egrep '\[.+\]\(.+\.md\)' "${filename}" | | |
sed -E 's,.*\[.+\]\((.+)\.md\).*,\1,' | | |
egrep -v '(ComparableValues|BaseAccount|Vxdigit)' | |
) | |
for related_rule in ${related_rules}; do | |
REFERENCES[${related_rule}]=${REFERENCES[${related_rule}]}:${rule} | |
done | |
REFERENCES[${rule}]="${REFERENCES[${rule}]}:$(tr '\n' ':' <<< ${related_rules})" | |
done < <(find rules -type f) | |
for rule in ${!REFERENCES[@]}; do | |
declare filename="rules/${rule}.md" | |
declare links=$(egrep '^\[.+\]: .+' "${filename}") | |
declare see_also=$( | |
tr ':' '\n' <<< ${REFERENCES[${rule}]} | | |
sort -u | | |
grep -v '^$' | | |
grep -v "^${rule}$" | | |
sed -E 's,(.+),- [\1](\1.md),g' | |
) | |
if [[ -z "${see_also}" ]]; then | |
continue; | |
fi | |
{ | |
sed -nE '/^# /,/^\*\*\*$/p' "${filename}" | |
echo "See also:" | |
echo | |
echo "${see_also}" | |
if [[ ! -z "${links}" ]]; then | |
echo | |
echo "${links}" | |
fi | |
} > "/tmp/doc" | |
cat /tmp/doc > "${filename}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment