Skip to content

Commit

Permalink
toc: clarify that INTRO, OUTRO er files, not text
Browse files Browse the repository at this point in the history
  • Loading branch information
holyjak authored and halostatue committed Jul 19, 2024
1 parent b39145e commit 01c2de2
Showing 1 changed file with 36 additions and 40 deletions.
76 changes: 36 additions & 40 deletions src/_adr_generate_toc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ eval "$("$(dirname "$0")/adr-config")"
## Options:
##
## -s include the state of each decision next to its link.
## -i INTRO precede the table of contents with the given INTRO text.
## -o OUTRO follow the table of contents with the given OUTRO text.
## -i INTRO precede the table of contents with text from the INTRO file.
## -o OUTRO follow the table of contents with text from the given OUTRO file.
## -p LINK_PREFIX
## prefix each decision file link with LINK_PREFIX.
##
Expand All @@ -19,55 +19,51 @@ eval "$("$(dirname "$0")/adr-config")"
link_prefix=
output_status=

while getopts si:o:p: arg
do
case "$arg" in
s)
output_status=1
shift
;;
i)
intro="$OPTARG"
;;
o)
outro="$OPTARG"
;;
p)
link_prefix="$OPTARG"
;;
esac
while getopts si:o:p: arg; do
case "$arg" in
s)
output_status=1
shift
;;
i)
intro="$OPTARG"
;;
o)
outro="$OPTARG"
;;
p)
link_prefix="$OPTARG"
;;
esac
done

cat <<EOF
# Architecture Decision Records
EOF

if [ ! -z "$intro" ]
then
cat "$intro"
echo
if [ ! -z "$intro" ]; then
cat "$intro"
echo
fi

for f in $("$adr_bin_dir/adr-list")
do
title=$("$adr_bin_dir/_adr_title" "$f")
link=${link_prefix}$(basename "$f")
status=
for f in $("$adr_bin_dir/adr-list"); do
title=$("$adr_bin_dir/_adr_title" "$f")
link=${link_prefix}$(basename "$f")
status=

if [[ "$output_status" == "1" ]]; then
# We're only interested in the first line of the status (e.g. Accepted).
# Second line, if any, will be a reference to another ADR that supersedes
# this record, that this record supersedes or that amends it.
# Additionally, prefix ADR links if prefix specified.
status=": $("$adr_bin_dir/_adr_status" $f | head -n 1 | sed -E -e "s/\((.+\.md)\)/(${link_prefix//\//\\/}\1)/")"
fi
if [[ "$output_status" == "1" ]]; then
# We're only interested in the first line of the status (e.g. Accepted).
# Second line, if any, will be a reference to another ADR that supersedes
# this record, that this record supersedes or that amends it.
# Additionally, prefix ADR links if prefix specified.
status=": $("$adr_bin_dir/_adr_status" $f | head -n 1 | sed -E -e "s/\((.+\.md)\)/(${link_prefix//\//\\/}\1)/")"
fi

echo -e "* [$title]($link)$status"
echo -e "* [$title]($link)$status"
done

if [ ! -z "$outro" ]
then
echo
cat "$outro"
if [ ! -z "$outro" ]; then
echo
cat "$outro"
fi

0 comments on commit 01c2de2

Please sign in to comment.