Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/_adr_generate_toc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ eval "$($(dirname $0)/adr-config)"
##
## -i INTRO precede the table of contents with the given INTRO text.
## -o OUTRO follow the table of contents with the given OUTRO text.
## -p LINK_PREFIX
## -p LINK_PREFIX
## prefix each decision file link with LINK_PREFIX.
## -r list the records in reverse order
##
## Both INTRO and OUTRO must be in Markdown format.

args=$(getopt i:o:p: $*)
args=$(getopt i:o:p:r $*)
set -- $args

link_prefix=
list_args=()

for arg
do
Expand All @@ -36,6 +38,10 @@ do
link_prefix="$2"
shift 2
;;
-r)
list_args+=("-r")
shift
;;
--)
shift
break
Expand All @@ -54,7 +60,7 @@ then
echo
fi

for f in $("$adr_bin_dir/adr-list")
for f in $("$adr_bin_dir/adr-list" ${list_args[@]})
do
title=$("$adr_bin_dir/_adr_title" $f)
link=${link_prefix}$(basename $f)
Expand Down
26 changes: 24 additions & 2 deletions src/adr-list
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,37 @@
set -e
eval "$($(dirname $0)/adr-config)"

## usage: adr list
## usage: adr list [-r]
##
## Lists the architecture decision records
##
## Options:
##
## -r list decision records in reverse order

adr_dir=$("$adr_bin_dir/_adr_dir")

sort_args=()

if (( $# > 0 )); then
while getopts ":r" arg; do
case "${arg}" in
r)
sort_args+=("-r")
;;

*)
echo "invalid argument: $OPTARG" >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
fi

if [ -d $adr_dir ]
then
find $adr_dir | grep -E "^$adr_dir/[0-9]+-[^/]*\\.md" | sort
find $adr_dir | grep -E "^$adr_dir/[0-9]+-[^/]*\\.md" | sort ${sort_args[@]}
else
echo "The $adr_dir directory does not exist"
exit 1
Expand Down
6 changes: 6 additions & 0 deletions tests/generate-contents.expected
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ adr generate toc
* [1. First Decision](0001-first-decision.md)
* [2. Second Decision](0002-second-decision.md)
* [3. Third Decision](0003-third-decision.md)
adr generate toc -r
# Architecture Decision Records

* [3. Third Decision](0003-third-decision.md)
* [2. Second Decision](0002-second-decision.md)
* [1. First Decision](0001-first-decision.md)
1 change: 1 addition & 0 deletions tests/generate-contents.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ adr new First Decision
adr new Second Decision
adr new Third Decision
adr generate toc
adr generate toc -r
5 changes: 4 additions & 1 deletion tests/list-records.expected
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ adr list
doc/adr/0001-first.md
doc/adr/0002-second.md
doc/adr/0003-third.md

adr list -r
doc/adr/0003-third.md
doc/adr/0002-second.md
doc/adr/0001-first.md
2 changes: 1 addition & 1 deletion tests/list-records.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ adr new second
adr list
adr new third
adr list

adr list -r