Skip to content

Instantly share code, notes, and snippets.

@henriquemoody
Created December 11, 2018 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henriquemoody/2496ab71c044e276c48622c9e7216304 to your computer and use it in GitHub Desktop.
Save henriquemoody/2496ab71c044e276c48622c9e7216304 to your computer and use it in GitHub Desktop.
Updates "See also" section for the Respect\Validation rules.
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